2012-09-27 8 views
9

設定で設定したiOS 6のFacebookと3.1のFacebook SDKを使用しています。FacebookのiOS SDKのopenActiveSessionの後に期限切れになったアクセストークン

これは完璧に実行されます。私は、私はエラーを取得していた情報「私」を取得しようとすると、

[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *fbSession, FBSessionState fbState, NSError *error) { ... } 

しかし今:

com.facebook.sdk:ParsedJSONResponseKey = { 
    body =  { 
     error =   { 
      code = 190; 
      "error_subcode" = 463; 
      message = "Error validating access token: Session has expired at unix time 1348704000. The current unix time is 1348706984."; 
      type = OAuthException; 
     }; 
    }; 
    code = 400; 
} 

を私は[error code]を見れば、それは5に等しいです。ログインした後に有効なアクセストークンを持ってはいけませんか?再認証する必要がありますか?

更新:再認証は役に立ちません。奇妙なことに、私のactiveSessionのaccessTokenは常に同じように戻ってきます。これはcloseAndClearTokenを呼び出しているにもかかわらず

+2

診断を開始するには、取得したaccess_tokenをログに記録してhttps://developers.facebook.com/tools/debugに貼り付けることができますか?そこにはタイムスタンプがありますか? –

+0

良いチップ。今問題はなくなり、私はそれを再現する必要があります。私は次回にあなたの提案を試してみます。 –

+0

iPhone5/iOS6で同じ問題が発生しています。それは非常に散発的だと思われる。この問題について何かを見つけたら教えてください。私も同じことをします。 – Chad

答えて

4

UPDATE: この問題は、FacebookのiOSのSDK 3.1.1で解決されています。


私はgithubののオフコードを同期化して、彼らはどこにもaccountStore renewCredentialsForAccount:completion:を呼び出していなかったことがわかりました。私はauthorizeUsingSystemAccountStoreで次のコードを変更し、問題を解決したようです。

// we will attempt an iOS integrated facebook login 
[accountStore requestAccessToAccountsWithType:accountType 
             options:options 
            completion:^(BOOL granted, NSError *error) { 

             // this means the user has not signed-on to Facebook via the OS 
             BOOL isUntosedDevice = (!granted && error.code == ACErrorAccountNotFound); 

             dispatch_block_t postReauthorizeBlock = ^{ 
              NSString *oauthToken = nil; 
              if (granted) {                          
               NSArray *fbAccounts = [accountStore accountsWithAccountType:accountType]; 
               id account = [fbAccounts objectAtIndex:0]; 
               id credential = [account credential];             
               oauthToken = [credential oauthToken]; 
              } 

              // initial auth case 
              if (!isReauthorize) { 
               if (oauthToken) { 
                _isFacebookLoginToken = YES; 
                _isOSIntegratedFacebookLoginToken = YES; 

                // we received a token just now 
                self.refreshDate = [NSDate date]; 

                // set token and date, state transition, and call the handler if there is one 
                [self transitionAndCallHandlerWithState:FBSessionStateOpen 
                        error:nil 
                        token:oauthToken 
                // BUG: we need a means for fetching the expiration date of the token 
                      expirationDate:[NSDate distantFuture] 
                       shouldCache:YES 
                       loginType:FBSessionLoginTypeSystemAccount]; 
               } else if (isUntosedDevice) { 
                // even when OS integrated auth is possible we use native-app/safari 
                // login if the user has not signed on to Facebook via the OS 
                [self authorizeWithPermissions:permissions 
                    defaultAudience:defaultAudience 
                    integratedAuth:NO 
                     FBAppAuth:YES 
                     safariAuth:YES 
                     fallback:YES 
                    isReauthorize:NO]; 
               } else { 
                // create an error object with additional info regarding failed login 
                NSError *err = [FBSession errorLoginFailedWithReason:nil 
                           errorCode:nil 
                          innerError:error]; 

                // state transition, and call the handler if there is one 
                [self transitionAndCallHandlerWithState:FBSessionStateClosedLoginFailed 
                        error:err 
                        token:nil 
                      expirationDate:nil 
                       shouldCache:NO 
                       loginType:FBSessionLoginTypeNone]; 
               } 
              } else { // reauth case 
               if (oauthToken) { 
                // union the requested permissions with the already granted permissions 
                NSMutableSet *set = [NSMutableSet setWithArray:self.permissions]; 
                [set addObjectsFromArray:permissions]; 

                // complete the operation: success 
                [self completeReauthorizeWithAccessToken:oauthToken 
                      expirationDate:[NSDate distantFuture] 
                       permissions:[set allObjects]]; 
               } else { 
                // no token in this case implies that the user cancelled the permissions upgrade 
                NSError *error = [FBSession errorLoginFailedWithReason:FBErrorReauthorizeFailedReasonUserCancelled 
                           errorCode:nil 
                           innerError:nil]; 
                // complete the operation: failed 
                [self callReauthorizeHandlerAndClearState:error]; 

                // if we made it this far into the reauth case with an untosed device, then 
                // it is time to invalidate the session 
                if (isUntosedDevice) { 
                 [self closeAndClearTokenInformation]; 
                } 
               } 
              } 
             }; 



             if (granted) { 
              [accountStore renewCredentialsForAccount:[[accountStore accountsWithAccountType:accountType] lastObject] completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { 
               dispatch_async(dispatch_get_main_queue(), postReauthorizeBlock); 
              }]; 
             } else { 
              // requestAccessToAccountsWithType:options:completion: completes on an 
              // arbitrary thread; let's process this back on our main thread 
              dispatch_async(dispatch_get_main_queue(), postReauthorizeBlock); 
             } 

            }]; 

} 
+0

更新する前に(更新に時間がかかります)、Appleのドキュメント(http://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountCredentialClassRef /Reference/Reference.html#//apple_ref/doc/c_ref/ACAccountCredential)、expiryDateパラメータが存在しないようです。 –

+2

こんにちはベン、あなたはrenew *に電話するのが必要です。ここからの呼び出しはうまくいきます。通話を行う場所の選択は、一般に、行動の一貫性と追加のネットワークラウンドトリップとの間のトレードオフに依存します。次のSDKアップデートでは、無効なトークンを処理するFBRequestConnectionロジックで呼び出しを行うことを検討しています。 –

+0

@JasonClarkそれは合理的な選択のようだ。私はまた、FB SDKのプレーンな古い更新呼び出しを持つことをお勧めします。これは、グラフ呼び出しを行うためのコンジットではなく、単にSDKをトークン管理に使用している場合に便利です。応答していただきありがとうございます! –

0

これは解決されていますが、デバイスを信頼できないため、私のバックエンドから私に電話しています。

したがって、私はFBSession+ (void)renewSystemAuthorizationに、認証エラーでバックエンドが戻ったときに電話します。

+1

3.1.1のFBSessionでrenewSystemAuthorizationクラスメソッドが表示されません。 – gerry3

+0

私が後にしているこのコミットにつき、彼らがこの問題に対処しているように見えます。 https://github.com/facebook/facebook-ios-sdk/commit/0b3d28b7bea8b63dd9efca67e1438d72fc78daf5 – hawflakes

関連する問題