简体   繁体   中英

How to handle expired Facebook access tokens on iOS and FB SDK 3.7

I'm using Facebook's iOS SDK 3.7 on my iOS app to handle logins. When I request post permissions it looks like the expiration date is about 2 months from the date of login.

I understand I can check the expiration date using [FBSession activeSession].accessTokenData.expirationDate but what happens, and how do I handle the token when the token expires?

Do I run [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:]; again?

I do this and FB recreates the session automatically. If FB has changed terms of use or something, then it shows login dialog to the user.

// call this before any calls to FB api
- (void)openSession
{
 if(FBSession.activeSession.state != FBSessionStateOpen)
{

    [FBSession openActiveSessionWithPublishPermissions:@[FB_PUBLISH_ACTIONS_PREMISSION]
                                       defaultAudience:FBSessionDefaultAudienceFriends
                                          allowLoginUI:NO
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                    if(!error && session.isOpen)
                    {
                    }
                    else
                    {
                        _lastError = error;
                        // handle the error
                    }
                       // here, you can handle the session state changes in switch case or
                      //something else
                    [self session:session
                  hasChangedState:status
                        withError:error];

                }];
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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