允许Facebook个人资料权限

时间:2013-04-23 11:31:05

标签: ios objective-c facebook

我想实现与朋友粉碎游戏相同的Facebook authentication概念。

在此如果用户通过iOS Facebook应用程序登录Facebook,则它仅要求用户访问基本个人资料信息。从上面链接有一些步骤在朋友粉碎游戏中实现这个概念。我想在我的原生应用中添加它。但无法知道如何做到这一点。如果有人知道这个,请帮助我。我非常感谢你。

1 个答案:

答案 0 :(得分:3)

登录时,使用:

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

// Attempt to open the session. If the session is not open, show the user the Facebook login UX
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true completionHandler:^(FBSession *session,
                                                 FBSessionState status, 
                                                 NSError *error)  

如果您的“权限”数组为nil,则它仅请求对用户配置文件的基本访问权限。如果您需要其他权限,只需在权限数组上添加想要的权限即可。可以在此处找到有效值:https://developers.facebook.com/docs/howtos/ios-6/,例如“email”,“user_birthday”,“user_location”,“user_about_me”等。

请注意,登录/请求读取权限时,您无法请求发布权限。这必须在登录后执行。您可以检查用户是否已经拥有所请求的权限(如发布一个),如果他/她拥有,则发布内容;如果没有,请求:

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
    // If the user doesn't have the publishing permission, tries to request it befor sharing

    [FBSession.activeSession
     requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
     defaultAudience:FBSessionDefaultAudienceFriends
     completionHandler:^(FBSession *session, NSError *error) {
         if (!error) {
             // Tries to share the content again, assuming we now have the permission
             (...)
         } else {
             // Couldn't get the required Permissions
         }
     }];

} else {
    // If the user already have the permissions, tries to publish the content
    (...)
}

有关发布内容的更多信息,请在此处查找“requestNewPublishPermissions”:https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/