2013-10-23 9 views
6

は私がキャッシュされtokenData理由:「FBSession:現在の状態からのトークンデータからセッションを開くことができません」

からのFacebookへのセッションを開きたいが、私はこのエラーで落ちる:理由:「FBSession:開くことができませんその現在の状態」からトークンデータからセッション

私のコード:

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 

} 

答えて

1

アクセストークンは、一般的に定められた時間間隔などの後に期限切れになります。 1時間 。 theresのキャッシュされたトークン情報、あなたはそれをあなたの道を開くしようとすることができ、ブロックが他のブロックに、その後失敗した場合ならば、あなたはそれをクリアして使用して新しいセッションを開こうとすることができる場合:

// 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]; 
    }]; 
関連する問題