private static IContact Translate(string response, string accessToken) { var xDoc = XDocument.Parse(response); var entryXName = XName.Get("entry", "http://www.w3.org/2005/Atom"); var xContactEntry = xDoc.Root.Element(entryXName); if (xContactEntry == null) throw new InvalidOperationException(); //TODO: Support not finding anything. var result = new Contact(); result.Title = XPathString(xContactEntry, "x:title", Ns); result.FullName = XPathString(xContactEntry, "gd:name/gd:fullName", Ns); result.DateOfBirth = xContactEntry.Elements(ToXName("gContact", "birthday")) .Select(x => (DateTime?)x.Attribute("when")) .FirstOrDefault(); result.Image = xContactEntry.Elements(ToXName("x", "link")) .Where(x => x.Attribute("rel") != null && x.Attribute("rel").Value == "http://schemas.google.com/contacts/2008/rel#photo" && x.Attribute("type") != null && x.Attribute("type").Value == "image/*" && x.Attribute("href") != null) .Select(x => x.Attribute("href")) .Where(att => att != null) .Select(att => { var hrp = new HttpRequestParameters(att.Value); hrp.QueryStringParameters.Add("access_token", accessToken); return hrp.ConstructUri(); }) .FirstOrDefault(); //<gd:email rel='http://schemas.google.com/g/2005#home' address='*****@*****.**' primary='true'/> var emails = from xElement in xContactEntry.XPathSelectElements("gd:email", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Attribute("address").Value); result.EmailAddresses.AddRange(emails); //<gd:phoneNumber rel='http://schemas.google.com/g/2005#mobile' uri='tel:+33-6-43-06-76-58' primary='true'>+33 6 4306 7658</gd:phoneNumber> var phoneNumbers = from xElement in xContactEntry.XPathSelectElements("gd:phoneNumber", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Value); result.PhoneNumbers.AddRange(phoneNumbers); /*<gd:organization rel='http://schemas.google.com/g/2005#work'><gd:orgName>Technip</gd:orgName></gd:organization>*/ var organizations = from xElement in xContactEntry.XPathSelectElements("gd:organization", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.XPathSelectElement("gd:orgName", Ns).Value); result.Organizations.AddRange(organizations); //<gContact:relation rel='partner'>Anne</gContact:relation> var relationships = from xElement in xContactEntry.XPathSelectElements("gContact:relation", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Value); result.Relationships.AddRange(relationships); return result; }