iOS Facebook SDK - Check Permissions

10,186

Solution 1

This question is a bit old but you can now check what permissions the active session has without making a graph request. Here is how it's done in the HelloFacebookSample :

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
    // permission does not exist
} else {
    // permission exists
}

Just replace "publish_actions" with "email".

Solution 2

SDK not providing direct method for checking specific permissions but you can check if user granted permission to your application by checking permissions connection of user object in Graph API

GET https://graph.facebook.com/me/permissions

Same can be achieved with FQL query on permissions table

SELECT email FROM permissions WHERE uid = me()
Share:
10,186
Giorgio Marziani de Paolis
Author by

Giorgio Marziani de Paolis

Sr. Solutions Architect @ Amazon Italia

Updated on July 27, 2022

Comments

  • Giorgio Marziani de Paolis
    Giorgio Marziani de Paolis almost 2 years

    I have a Facebook SSO working perfectly on my app, using last release of Facebook Objective-C SDK. I need to ask an extra permission inside the app if user do "something". I don't need to ask that permission if user gave it to me before, so, I guess, in Facebook SDK there should be a method

    -(BOOL) checkPermission:(NSString*) permission;
    

    so I can use it like this:

    if( [facebook checkPermission:@"email"] ) {
    

    Is there a way to do this?

  • Giorgio Marziani de Paolis
    Giorgio Marziani de Paolis over 12 years
    Thank you, based on your answer, I tried using the method [facebook requestWithGraphPath:@"me/permissions" andDelegate:self];. Implementing the delegate method it works perfectly. Thank you again
  • Smikey
    Smikey about 12 years
    Could you add the code for your method to determine if the e-mail permission was active or not? What will 'email' be if the permission is granted?
  • Ferran Maylinch
    Ferran Maylinch almost 10 years
    [FBSession activeSession].permissions returns the permissions you requested, not the active ones. Or at least that's what I saw. See my answer below. You need [FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:...].
  • Raphaël Agneau de Selve
    Raphaël Agneau de Selve almost 10 years
    I cannot test right now but the documentation says otherwise : "The permissions granted to the access token during the authentication flow." developers.facebook.com/docs/reference/ios/current/class/…
  • Ferran Maylinch
    Ferran Maylinch almost 10 years
    Today I updated my Facebook SDK pod from 3.9.0 to 3.15.1 and now [FBSession activeSession].permissions returns the right permissions and [FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:...] doesn't return them anymore (now it returns {status:granted, permission:installed}).