reason: 'FBSession: cannot open a session from token data from its current state'

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

}

Answers


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

Need Your Help

How add Javascript in GVnix/Spring roo project

javascript java spring jsp gvnix

I'm developing a web application and I want add a js file in my project to use it. I tried to add in this way:

Why std::thread accepts a functor by forwarding reference

c++ multithreading c++11 c++14 forwarding-reference

Why does a std::thread object accept the function parameter by forwarding reference and then make a copy of the object with decay_copy? Wouldn't it be easier to just accept the function object by ...