Last active
October 4, 2016 19:35
-
-
Save jmelosegui/91310a23b63b0169440c260ecedef4be to your computer and use it in GitHub Desktop.
Gets a Picasa user, hence a google user, using an email address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO;; | |
using System.Net; | |
using System.Xml.Serialization; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Write(GetPicasaUserByEmail([YOUR EMAIL HERE])); | |
Console.Read(); | |
} | |
public static GoogleUser GetPicasaUserByEmail(string email) | |
{ | |
if (string.IsNullOrWhiteSpace(email)) | |
{ | |
throw new ArgumentException("Parameter email cannot be null nor empty"); | |
} | |
var endpoint = $"http://picasaweb.google.com/data/entry/api/user/{email}"; | |
var client = new WebClient(); | |
byte[] buffer = client.DownloadData(endpoint); | |
GoogleUser googleUser = null; | |
using (var ms = new MemoryStream(buffer)) | |
{ | |
XmlSerializer serializer = new XmlSerializer(typeof(GoogleUser)); | |
googleUser = (GoogleUser)serializer.Deserialize(ms); | |
} | |
return googleUser; | |
} | |
} | |
[XmlRoot("entry", Namespace = "http://www.w3.org/2005/Atom")] | |
public class GoogleUser | |
{ | |
[XmlElement("id")] | |
public string Id { get; set; } | |
[XmlElement("published")] | |
public DateTime PublishedUtcDate { get; set; } | |
[XmlElement("updated")] | |
public DateTime UpdatedUtcDate { get; set; } | |
[XmlElement("category")] | |
public string Category { get; set; } | |
[XmlElement("title")] | |
public string Title { get; set; } | |
[XmlElement("summary")] | |
public string Summary { get; set; } | |
[XmlElement("link")] | |
public List<Link> Links { get; set; } | |
[XmlElement("author")] | |
public Author Author { get; set; } | |
[XmlElement("user", Namespace = "http://schemas.google.com/photos/2007")] | |
public string UserId { get; set; } | |
[XmlElement("nickname", Namespace = "http://schemas.google.com/photos/2007")] | |
public string NickName { get; set; } | |
[XmlElement("thumbnail", Namespace = "http://schemas.google.com/photos/2007")] | |
public string ThumbnailUrl { get; set; } | |
} | |
public class Author | |
{ | |
[XmlElement("name")] | |
public string Name { get; set; } | |
[XmlElement("uri")] | |
public string PicasaUrl { get; set; } | |
} | |
public class Link | |
{ | |
[XmlAttribute("rel")] | |
public string Relationship { get; set; } | |
[XmlAttribute("type")] | |
public string Type { get; set; } | |
[XmlAttribute("href")] | |
public string Url { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment