Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created August 13, 2011 21:15
Show Gist options
  • Save prabirshrestha/1144259 to your computer and use it in GitHub Desktop.
Save prabirshrestha/1144259 to your computer and use it in GitHub Desktop.
check if the specified access token has enough permission
/// <returns>returns null is doesn't have enough permission</returns>
public string[] HasPermissions(string accessToken, string[] permissions)
{
try
{
var fb = new FacebookClient(accessToken);
var remoteResult = ((IDictionary<string, object>)fb.Get("me/permissions"));
if (remoteResult != null && remoteResult.ContainsKey("data"))
{
var data = remoteResult["data"] as IList<object>;
if (data != null && data.Count > 0)
{
var permData = data[0] as IDictionary<string, object>;
return permData == null
? new string[0]
: (permData.Where(perm => perm.Value.ToString() == "1").Select(perm => perm.Key)).ToArray();
}
}
}
catch (FacebookOAuthException)
{
return null;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment