Facebook访问令牌已过期 - iOS 6社交框架

Mar*_*cas 9 facebook-graph-api facebook-access-token ios6

我正在制作一个基于iOS6社交框架的应用程序...它工作正常但现在几个月后出现了一个奇怪的错误.

我导入的JSON Facebook数据的NSLog到NSDictionary是:

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;
Run Code Online (Sandbox Code Playgroud)

似乎我的访问令牌已过期,但iOS6社交框架是不是应该自动处理它?

有关如何解决它的任何想法,也避免了未来的问题,所以我可以安全地发布一个真正的应用程序?

Mar*_*cas 13

终于搞定了...有必要检查NSDictionary是否有一个名为"error"的对象(在这种情况下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);
        }
    }];
}
Run Code Online (Sandbox Code Playgroud)