Request additional permission Facebook SDK 4 iOS

2020-03-26 09:00发布

问题:

I have an app that log in through facebook. When it log in, I only asked for "public_profile", "user_friends" and "email" permission. I know that I can ask for more permission later on, as FB stated:

"Your app can ask for additional permissions at any time, even after a person logs in for the first time. For example, the publish_actions permission lets you post to a person's Facebook Timeline. It's recommended you ask for this permission only when a person is ready to publish a story to Facebook."

So when I was about to post to user's wall, I want to ask for "publish_actions". Please tell me how to do it with Facebook SDK 4. Most of the answer relating to FBSession, activeSession, requestNewPublishPermissions, etc., but in latest Facebook SDK (4.1.0), there is no FBSession class.

回答1:

You have to call login method again to request another permission.

FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
                                  handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
 {
     if ([result.declinedPermissions containsObject:@"publish_actions"])
     {
         // permission denied
     }
     else
     {
         // do something
     }
 }];


回答2:

For Parse Developer, it can be an answer.

PFFacebookUtils.linkUserInBackground(user, withPublishPermissions: ["publish_actions"], {
  (succeeded: Bool?, error: NSError?) -> Void in
  if succeeded {
    println("User now has read and publish permissions!")
  }
})

But I am still looking for a more general solution