I want to open a session to facebook from a cached tokenData
but i fall on this error: reason: 'FBSession: cannot open a session from token data from its current state'
my code :
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 generally expire after a stipulated time interval eg. 1 hour . If theres any cached token info then you can try to open it your way and if the if block fails then in the else block you can try to clear it and open an 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];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With