Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook iOS SDK won't open login UI after user changes password (iOS 6)

Some context: the user had previously installed the app, authorized FB, everything worked great, then they changed their FB password (through facebook.com), deleted the app, and have now reinstalled it and are running it for the first time again after reinstall.

I am calling [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler] with allowLoginUI: YES and the read permissions being "email, user_about_me, user_birthday, user_interests, user_location."

The FBSessionState I am getting in the completionHandler is FBSessionStateClosedLoginFailed. The NSLog of the error is this:

Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (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 "The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password." UserInfo=0x1cd5b970 {NSLocalizedDescription=The Facebook server could not fulfill this access request: Error validating access token: The session has been invalidated because the user has changed the password.}}

That internal error domain is ACErrorDomain and error code ACErrorPermissionDenied. So, how do I let the user re-authorize the app?

I have tried calling openActiveSessionWithReadPermissions again but that just keeps outputting the same error. I have also tried [FBSession.activeSession closeAndClearTokenInformation] but that doesn't seem to do anything (presumably because there is no activeSession).

like image 899
Arthur N Avatar asked Feb 02 '13 02:02

Arthur N


People also ask

Why does my Facebook not let me log in?

If you're having trouble logging into your Facebook account from your Facebook app: Make sure that you have the latest version of the Facebook app, or delete the app and then reinstall it. Try logging in from a mobile browser (example: Safari, Chrome).

Does Facebook SDK use IDFA?

The Facebook SDK includes code to access Apple's Advertising Identifier (IDFA), but that code is only executed in certain situations.


1 Answers

Hitting a very similar sort of bug with 3.2.1 Facebook SDK. In my case, I get into FBSessionStateOpen but have been given an invalid access token. As the question states, the normal closeAndClearTokenInformation and even deleting the app doesn't fix it. The only way I have been able to get-back-in under this scenario is to have the user change their password in the setting app. So this is what I do.

// 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.
     }
 }];

This is the only pragmatic solution I have been able to come up with.

like image 135
Ray Fix Avatar answered Sep 20 '22 16:09

Ray Fix