public static OpenAuthUser GetUserInfo(string accessToken) { string response = Request(HttpMethod.Get, UserInfoEndpoint, new List<Parameter> { new Parameter { Name = OAuth2Parameter.AccessToken.Value(), Value = accessToken } }); JObject data = JObject.Parse(response); var user = new OpenAuthUser { ID = data["id"].Value<string>(), FullName = data["name"].Value<string>(), FirstName = data["given_name"].Value<string>(), LastName = data["family_name"].Value<string>(), DisplayName = data["name"].Value<string>(), Link = data["link"] != null ? data["link"].Value<string>() : null, Email = data["email"] != null ? data["email"].Value<string>() : null, // PictureUrl = string.Format("https://profiles.google.com/s2/photos/profile/{0}", data["id"].Value<string>()) }; if (data["gender"] != null) { switch (data["gender"].Value<string>()) { case "male": user.Gender = OpenAuthGender.Male; break; case "female": user.Gender = OpenAuthGender.Female; break; } } return user; }
public static OpenAuthUser GetUserInfo(string accessToken) { string response = Request(HttpMethod.Get, UserInfoEndpoint, new List<Parameter> { new Parameter { Name = OAuth2Parameter.AccessToken.Value(), Value = accessToken } }); var data = JObject.Parse(response); var user = new OpenAuthUser { ID = data["id"].Value<string>(), FullName = data["name"].Value<string>(), FirstName = data["first_name"].Value<string>(), LastName = data["last_name"].Value<string>(), Link = data["link"].Value<string>(), Email = data["emails"]["preferred"].Value<string>() }; switch (data["gender"].Value<string>()) { case "male": user.Gender = OpenAuthGender.Male; break; case "female": user.Gender = OpenAuthGender.Female; break; } return user; }
public static OpenAuthUser GetUserInfo(string accessToken) { string response = Request(HttpMethod.Get, UserInfoEndpoint, new List<Parameter> { new Parameter { Name = OAuth2Parameter.AccessToken.Value(), Value = accessToken } }); JObject data = JObject.Parse(response); var user = new OpenAuthUser { ID = data["id"].Value<string>(), FullName = data["name"].Value<string>(), FirstName = data["first_name"].Value<string>(), LastName = data["last_name"].Value<string>(), DisplayName = data["name"].Value<string>(), Email = data["email"] != null ? data["email"].Value<string>() : null, Link = data["link"].Value<string>(), Gender = data["gender"] != null ? data["gender"].Value<string>() == "male" ? OpenAuthGender.Male : OpenAuthGender.Female : (OpenAuthGender?)null, PictureUrl = string.Format("http://graph.facebook.com/{0}/picture?type=large", data["id"].Value<string>()) }; if (data["hometown"] != null) user.Location = data["hometown"]["name"].Value<string>(); else if (data["location"] != null) user.Location = data["location"]["name"].Value<string>(); return user; }