Facebook iOS SDK请求权限publish_actions,但用户需要再次输入密码

时间:2015-02-09 03:32:43

标签: ios facebook permissions facebook-login facebook-permissions

在我的项目中使用了Facebook iOS SDK 3.8,现在我将其升级到3.22。

在请求“publish_actions”权限期间发生了一件奇怪的事情,即用户需要再次输入她的帐户和密码。在之前的版本中,只会跳过“再次登录”部分。我想知道Facebook SDK中的逻辑是否发生了变化,或者我是否需要更改会话处理流程。关于这个问题的任何想法?

我以前申请“publish_actions”权限的方式是:

 [activeSession openWithBehavior: FBSessionLoginBehaviorForcingWebView
        completionHandler:^(FBSession *session,
                            FBSessionState state, NSError *error) {
    [session reauthorizeWithPermissions:@[@"publish_actions"]
                                                                        isRead:NO
                                                                      behavior:FBSessionLoginBehaviorForcingWebView
                                                               defaultAudience:FBSessionDefaultAudienceFriends
                                                             completionHandler:^(FBSession *session, NSError *error) {
 }

我也试过

[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                          defaultAudience:FBSessionDefaultAudienceFriends
                                    completionHandler:^(FBSession *session, NSError *error) {
                                        __block NSString *alertText;
                                        __block NSString *alertTitle;
                                        _reauthorizeInProgress = YES;
                                        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

                                            }

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

1 个答案:

答案 0 :(得分:1)

此行为是Facebook设置的默认行为。文件https://developers.facebook.com/docs/facebook-login/ios/v2.2说:

  

WebView的缺点是:

     

每次访问登录流程时,人们都必须填写登录凭据。

在FBSession.m文件中,我更改了方法

中的代码
- (void)retryableAuthorizeWithPermissions:(NSArray *)permissions
                      defaultAudience:(FBSessionDefaultAudience)defaultAudience
                       integratedAuth:(BOOL)tryIntegratedAuth
                            FBAppAuth:(BOOL)tryFBAppAuth
                           safariAuth:(BOOL)trySafariAuth
                             fallback:(BOOL)tryFallback
                        isReauthorize:(BOOL)isReauthorize
                  canFetchAppSettings:(BOOL)canFetchAppSettings

请求获得其他权限时不要删除cookie,替换

   // To avoid surprises, delete any cookies we currently have.
    [FBUtility deleteFacebookCookies];

    // To avoid surprises, delete any cookies we currently have.
if(!isReauthorize){
    [FBUtility deleteFacebookCookies];
}

我同意修改SDK源不是一个好主意,而我应该在用户体验和代码风格的一致性之间取得一些平衡。 ;(