2013-04-15 35 views
9

我正在製作基於iOS6社交框架的應用程序...它工作正常,但現在幾個月後出現了一個奇怪的錯誤。Facebook訪問令牌已過期 - iOS 6社交框架

進口JSON的Facebook數據到NSDictionary中的我的NSLog是:

profiledictionary: { 
error = { 
code = 190; 
"error_subcode" = 463; 
message = "Error validating access token: Session has expired at unix time 1365610034. The current unix time is 1366032783."; 
type = OAuthException; 

看來我的訪問令牌已過期,但並不iOS6的社會結構應該自動地照顧它?

任何關於如何解決這個問題的想法,以及避免這樣的未來問題,所以我可以安全地發佈一個真正的應用程序?

回答

13

終於得到了它......是必要的,以檢查是否有NSDictionary中的對象名爲「錯誤」(在這種情況下,Facebook的誤差約令牌過期),如果是這樣調用一個方法來更新ACAccount:

if([self.profileDictionary objectForKey:@"error"]!=nil) 
{ 
[self attemptRenewCredentials]; 
} 

-(void)attemptRenewCredentials{ 
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){ 
     if(!error) 
     { 
      switch (renewResult) { 
       case ACAccountCredentialRenewResultRenewed: 
        NSLog(@"Good to go"); 
        [self getFacebookAccount]; 
        break; 
       case ACAccountCredentialRenewResultRejected: 
        NSLog(@"User declined permission"); 
        break; 
       case ACAccountCredentialRenewResultFailed: 
        NSLog(@"non-user-initiated cancel, you may attempt to retry"); 
        break; 
       default: 
        break; 
      } 

     } 
     else{ 
      //handle error 
      NSLog(@"error from renew credentials%@",error); 
     } 
    }]; 
} 
+1

我今天提出了你的問題和答案。你剛剛救了我的皮膚!你在地球上發現了什麼?非常感謝。 – Douglas

+0

樂意幫忙;) –