2013-04-15 36 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

乐意帮忙;) –