Skip to content

Instantly share code, notes, and snippets.

@vgheri
Created March 24, 2014 09:35
Show Gist options
  • Save vgheri/9737178 to your computer and use it in GitHub Desktop.
Save vgheri/9737178 to your computer and use it in GitHub Desktop.
Verify Facebook Access Token
private async Task<FacebookUserViewModel> VerifyFacebookAccessToken(string accessToken)
{
FacebookUserViewModel fbUser = null;
var path = "https://graph.facebook.com/me?access_token=" + accessToken;
var client = new HttpClient();
var uri = new Uri(path);
var response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
fbUser = Newtonsoft.Json.JsonConvert.DeserializeObject<FacebookUserViewModel>(content);
}
//var response = await client.GetStringAsync(uri);
//if ()
//{
// fbUser = Newtonsoft.Json.JsonConvert.DeserializeObject<FacebookUserViewModel>(response);
//}
return fbUser;
}
public class FacebookUserViewModel
{
[JsonProperty("id")]
public string ID { get; set; }
[JsonProperty("first_name")]
public string FirstName { get; set; }
[JsonProperty("last_name")]
public string LastName { get; set; }
[JsonProperty("username")]
public string Username { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment