gpt4 book ai didi

ios - 社交 API Facebook iOS : "Error validating access token: Session has expired on"

转载 作者:行者123 更新时间:2023-11-28 19:02:55 26 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我将 Facebook API 与社交框架结合使用来发出与 Facebook 共享的请求,但现在我从 Facebook 收到此状态代码:

{
    error =     {
        code = 190;
        "error_subcode" = 463;
        message = "Error validating access token: Session has expired on 25 marzo 2014 16.20. The current time is 18 aprile 2014 8.45.";
        type = OAuthException;
    };
}

这是我使用的代码:

ACAccountType *facebookTypeAccount = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

NSDictionary *options = @{ACFacebookAppIdKey: @"##myfbid###",ACFacebookPermissionsKey: @[@"email"]};

[accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:options
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [accountStore accountsWithAccountType:facebookTypeAccount];
facebookAccount = [accounts lastObject];
//NSLog(@"Success");

NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
//this json conaints the log i write above
}

];

所以我尝试从 iPhone 设置中的 Facebook 帐户注销,然后再次登录,所以我的问题是有没有一种方法可以在每次打开应用程序时自动刷新此 token 以避免此问题?

最佳答案

您不能“自动”刷新访问 token 。每当您收到响应时,您应该检查错误,如果存在错误则更新 token 。此代码可以帮助您-

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

-(void)renewCredentials{
[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);
}
}];
}

希望对您有所帮助!

关于ios - 社交 API Facebook iOS : "Error validating access token: Session has expired on",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23157972/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com