Reason: "FBSession: cannot open a session from token data from the current state"
I want to open a session for facebook from cached tokenData p>
but I fall for this error: reason: "FBSession: cannot open a session from token data from the current state"
my code is:
FBAccessTokenData *savedAccessTokenData =[TokenCacheStrategy getSavedToken]; if(savedAccessTokenData!nil){ [appDelegate.session openFromAccessTokenData:savedAccessTokenData completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if(appDelegate.session.isOpen){ NSLog(@"session opened from saved access token"); NSLog(@"accesstoken: %@",[appDelegate.session.accessTokenData accessToken]); if(completionBlock!=NULL){ completionBlock(); } }//session is open from token data } access tokens usually expire after a given time interval, for example. 1 hour. If you have any cached information about tokens, then you can try to open it in your own way, and if the if block fails, then in the else block you can try to clear it and open a new session using:
// If the session state is any of the two "open" states when the button is clicked if (FBSession.activeSession.state == FBSessionStateOpen || FBSession.activeSession.state == FBSessionStateOpenTokenExtended) { // Close the session and remove the access token from the cache // The session state handler (in the app delegate) will be called automatically [FBSession.activeSession closeAndClearTokenInformation]; // If the session state is not any of the two "open" states when the button is clicked } else { // Open a session showing the user the login UI // You must ALWAYS ask for basic_info permissions when opening a session [FBSession openActiveSessionWithReadPermissions:@[@"basic_info"] allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { [self sessionStateChanged:session state:state error:error]; }];