用户更改密码后,iOS iOS SDK无法打开登录界面(iOS 6)

Art*_*r N 10 facebook-ios-sdk

一些上下文:用户以前安装了应用程序,授权FB,一切运行良好,然后他们更改了他们的FB密码(通过facebook.com),删除了应用程序,现在重新安装它,并在第一次运行后再次运行重新安装.

我正在调用[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler],allowLoginUI: YES读取权限为"email,user_about_me,user_birthday,user_interests,user_location".

FBSessionState我收到的completionHandlerIS FBSessionStateClosedLoginFailed.NSLog的错误是这样的:

Error Domain = com.facebook.sdk Code = 2"操作无法完成.(com.facebook.sdk error 2.)"UserInfo = 0x1cd68c00 {com.facebook.sdk:ErrorLoginFailedReason = com.facebook.sdk:ErrorLoginFailedReason ,com.facebook.sdk:ErrorInnerErrorKey = Error Domain = com.apple.accounts Code = 7"Facebook服务器无法满足此访问请求:验证访问令牌时出错:会话已失效,因为用户已更改密码." UserInfo = 0x1cd5b970 {NSLocalizedDescription = Facebook服务器无法满足此访问请求:验证访问令牌时出错:会话已失效,因为用户已更改密码.}}

该内部错误域是ACErrorDomain错误代码ACErrorPermissionDenied.那么,我该如何让用户重新授权该应用?

我已经尝试过openActiveSessionWithReadPermissions再次调用,但只是输出相同的错误.我也尝试了,[FBSession.activeSession closeAndClearTokenInformation]但似乎没有做任何事情(大概是因为没有activeSession).

Ray*_*Fix 12

使用3.2.1 Facebook SDK遇到类似的错误.在我的情况下,我进入FBSessionStateOpen但被赋予了无效的访问令牌.正如问题所述,正常的closeAndClearTokenInformation甚至删除应用程序都无法修复它.在这种情况下,我能够重新获得的唯一方法是让用户在设置应用程序中更改其密码.所以这就是我的工作.

// In my completion handler FBSessionStateOpen is called BUT an
// invalid accessToken was detected.

[session closeAndClearTokenInformation];
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, 
                                    NSError *error) 
  {
     if (result == ACAccountCredentialRenewResultFailed ||
         result == ACAccountCredentialRenewResultRejected)
     {
       [self showErrorMessage:NSLocalizedString(@"You may need to re-enter your Facebook password in the iPhone Settings App.\n", nil)];
     }
     else 
     {
        // attempt opening a session again  (after they have updated their account 
        // settings I end up here)

        [self facebookLogin];  // Performs openActiveSessionWithReadPermissions, 
                               // but this time around the token issued should be good.
     }
 }];
Run Code Online (Sandbox Code Playgroud)

这是我能够提出的唯一务实的解决方案.


com*_*ial 0

我认为您需要使用这样的代码获取新的访问令牌......

[FBSession.activeSession closeAndClearTokenInformation];
[[FBSession class] performSelector:@selector(renewSystemAuthorization)];
[FBSession openActiveSessionWithReadPermissions:nil
                               allowLoginUI:YES
                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

}
Run Code Online (Sandbox Code Playgroud)