繁体   English   中英

如何在iOS登录期间请求Facebook publish_actions权限

[英]How to request Facebook publish_actions permission during login in iOS

要在Android登录期间请求Facebook publish_actions权限,我需要

loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setPublishPermissions(“publish_actions”);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
    @Override
    public void onUserInfoFetched(GraphUser user) {
        FacebookOptInFragment.this.user = user;
        updateUI();
    }
});

这就是我需要做的,我已经完成。 用户将首先登录,然后提示您授予发布权限。 如何在iOS中执行完全相同的操作?

请注意,我刚刚下载了Facebook SDK,这意味着我拥有最新和最好的(如果相关)。

首先介绍一些文档

登录期间使用publish_actions请求发布权限会在登录UI中创建第二步。 因此,您应该在登录期间请求最低读取权限,然后在某人实际需要它们时请求任何其他权限或发布权限。 要优化您的权限请求,请参阅优化权限。

因此,如果您只需要授权您的iOS应用并授予publish_actions权限,并且您确实要与iOS Facebook帐户集成,则必须先获得阅读权限,然后才能获得发布权限。 请参阅上面页面链接的“ Request at Login portion以获取读取权限。

然后,您可以为publish_actions请求其他权限,例如

// Request publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                      defaultAudience:FBSessionDefaultAudienceFriends
                                    completionHandler:^(FBSession *session, NSError *error) {
                                      __block NSString *alertText;
                                      __block NSString *alertTitle;
                                      if (!error) {
                                        if ([FBSession.activeSession.permissions 
                                             indexOfObject:@"publish_actions"] == NSNotFound){
                                          // Permission not granted, tell the user we will not publish
                                          alertTitle = @"Permission not granted";
                                          alertText = @"Your action will not be published to Facebook.";
                                          [[[UIAlertView alloc] initWithTitle:alertTitle
                                                          message:alertText
                                                         delegate:self
                                                cancelButtonTitle:@"OK!"
                                                otherButtonTitles:nil] show];
                                        } else {
                                          // Permission granted, publish the OG story
                                          [self publishStory];
                                        }

                                      } else {
                                        // There was an error, handle it
                                        // See https://developers.facebook.com/docs/ios/errors/
                                      }
                                    }];

同时检查文档的这一部分以进行权限管理

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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