facebook-graph-api - Facebook访问 token 已过期-iOS 6社交框架

标签 facebook-graph-api ios6 facebook-access-token

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

我将导入的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;

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

关于如何解决它以及避免将来出现此类问题的任何想法,这样我就可以安全地发布真实的应用程序了吗?

最佳答案

终于知道了...有必要检查NSDictionary是否有一个名为“错误”的对象(在这种情况下,有关 token 的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);
        }
    }];
}

关于facebook-graph-api - Facebook访问 token 已过期-iOS 6社交框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16024658/

相关文章:

php - 需要有关 OAuthException 代码 2500 的帮助

java - facebook4j graph api 将帖子的评论数量限制为 25

ios - 从 PerformBlock NPSPrivateQueueConcurrencyType 调用的方法中的 FetchRequest 失败

ios - 如何将 UIImage 选择器相机方向更改为横向?

iphone - 以编程方式在子类 UIView 的 subview 上自动布局

authorization - FB.login 返回无效的 OAuth 访问 token

java - 获取 Facebook 好友个人资料详细信息

facebook-graph-api - Facebook 图形 API 从 Pages 获取帖子

javascript - Facebook Credits Api实现

facebook - 无法使用指定的 access_token 访问应用程序