2012-09-27 24 views
9

के लिए ओपनएक्टिव सत्र के बाद समाप्त हो गया टोकन मैं आईओएस 6 फेसबुक के साथ 3.1 फेसबुक एसडीके का उपयोग कर रहा हूं और सेटिंग्स में मेरे ऐप को अधिकृत किया गया है।फेसबुक आईओएस एसडीके

यह दोषरहित कार्यान्वित:

[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 के बराबर है। लॉग इन करने के बाद मेरे पास वैध पहुंच टोकन नहीं होना चाहिए? क्या मुझे पुनः प्राधिकरण कॉल करने की आवश्यकता है?

अद्यतन: पुनर्लेखन सहायता नहीं करता है। अजीब रूप से मेरे सक्रिय सत्र के लिए पहुंच टोकन हमेशा वापस आ रहा है। यह बंद करने के बावजूद और क्लीयर टोकन।

+2

निदान शुरू करने के लिए, क्या आप इसे एक्सेस_टोकन लॉग कर सकते हैं और इसे https://developers.facebook.com/tools/debug में पेस्ट कर सकते हैं - क्या टाइमस्टैम्प सही है? –

+0

अच्छी टिप। अब समस्या चली गई है और मुझे इसे फिर से बनाने की जरूरत है। अगली बार जब मैं इसे देखूं तो मैं आपके सुझाव का प्रयास करूंगा। –

+0

मुझे आईफोन 5/आईओएस 6 के साथ एक ही समस्या है। हालांकि यह बहुत sporadic लगता है। अगर आपको इस मुद्दे के बारे में कुछ और मिलता है तो कृपया मुझे बताएं और मैं वही करूँगा। – Chad

उत्तर

4

अद्यतन: यह समस्या फेसबुक आईओएस एसडीके 3.1.1 में संबोधित किया गया।


मैं GitHub के बंद कोड synched और कहा कि वे 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

हमें नवीनीकरण से पहले एक समाप्ति तिथि की जांच करनी चाहिए (क्योंकि इसे नवीनीकरण करने में समय लगता है) लेकिन ऐप्पल के दस्तावेज़ों में यह क्या कहता है इसके बावजूद (http://developer.apple.com/library/ios/#documentation/Accounts/Reference/ACAccountCredentialClassRef /Reference/Reference.html#//apple_ref/doc/c_ref/ACAccountCredential), समाप्ति पैराम मौजूद नहीं है। –

+2

हाय बेन, आप नवीकरण * कॉल करने के लिए आवश्यक हैं। यहां से कॉलिंग अच्छी तरह से काम करता है। कॉल करने का विकल्प आम तौर पर व्यवहार में स्थिरता और अतिरिक्त नेटवर्क राउंडट्रिप्स के बीच व्यापार-बंद पर निर्भर करता है। अगले एसडीके अपडेट में हम FBRequestConnection तर्क में कॉल करने पर विचार कर रहे हैं जो अमान्य टोकन को संभालता है। –

+0

@JasonClark यह एक उचित विकल्प की तरह लगता है। मैं सुझाव देता हूं कि एफबी एसडीके में सिर्फ एक सादा पुराना नवीकरण कॉल भी हो। यह उपयोगी होगा अगर आप ग्राफ कॉल करने के लिए एक कंडिट के बजाए टोकन प्रबंधन के लिए केवल एसडीके का उपयोग कर रहे थे। उत्तर देने के लिये धन्यवाद! –

0

तो यह संबोधित है, लेकिन मैं अपने बैकएंड से बुला रहा है/मुझे आप डिवाइस भरोसा नहीं कर सकते क्योंकि सत्यापित करने के लिए।

तो मैं FBSession के + (void)renewSystemAuthorization पर कॉल करता हूं जब बैकएंड एक प्राधिकरण त्रुटि के साथ वापस आता है।

+1

मुझे 3.1.1 में FBSession में नवीनीकरण सिस्टम प्राधिकरण वर्ग विधि नहीं दिखाई दे रही है। – gerry3

+0

ऐसा लगता है कि उन्होंने इस प्रतिबद्धता के प्रति इस मुद्दे को संबोधित किया जिसके लिए मैं पीछे हूं। https://github.com/facebook/facebook-ios-sdk/commit/0b3d28b7bea8b63dd9efca67e1438d72fc78daf5 – hawflakes

संबंधित मुद्दे