简体   繁体   中英

iOS Facebook SDK 3.1 add permission when login

I am trying to follow the Facebook SDK 3.1 tutorial: Scrumptious and integrate FB to my app.

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {

NSArray *permissions = @[@"email"];

return [FBSession openActiveSessionWithReadPermissions:permissions
                                          allowLoginUI:allowLoginUI
                                     completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                                         [self sessionStateChanged:session state:state error:error];
                                     }];

I want to add extra permission however it only show the basic information in the authentication as the following image:

截图

I also used deprecated method and I got the same result:

[FBSession openActiveSessionWithPermissions:permissions allowLoginUI:allowLoginUI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
    [self sessionStateChanged:session state:state error:error];
}];

I found temporary solution from here by using reauthorizeWithPublishPermissions in somewhere else. The user have to login to the facebook twice to read the user email.

Is there any solution which I can do it in once?

Thanks for helping!

EDIT: Another post on stackoverflow, using openActiveSessionWithPublishPermissions , still have the same result as the screenshot.

According to the Facebook FBSession Reference , as a best practice, you should ask for read permissions when opening the session. And then ask for additional permissions later on, when you need them.

It is required that initial permissions requests represent read-only permissions only.

Secondly, I tried this code below, and I get the right permission requirement.

NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];

[FBSession openActiveSessionWithReadPermissions:permissions
                                   allowLoginUI:YES
                              completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
 [self sessionStateChanged:session state:state error:error];}];
 [permissions release];

Hope this helps.

I would check the permissions on Facebook.com in the Facebook app's permission settings and make sure they match. I do believe they say you can set the permissions in your iOS code, but I would recommend matching the permissions in the FB app settings as well.

http://developers.facebook.com/docs/reference/login/#permissions

this is an example how to use them

NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream", @"email", nil];
[facebook authorize:permissions];
[permissions release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM