Created
August 13, 2011 21:15
-
-
Save prabirshrestha/1144259 to your computer and use it in GitHub Desktop.
check if the specified access token has enough permission
This file contains hidden or 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
| /// <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