我正在尝试在我的应用程序中实现 facebook 登录并且它正在工作(我正在获取访问令牌),但是每当我尝试发出图形请求时,我都会收到以下消息,说我需要一个活动的访问令牌才能向图形 API 发出请求:
Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x6a99fa0 {
error=<CFBasicHash 0x6a99050 [0x1582b48]>{
type = mutable dict, count = 3,
entries =>
2 : <CFString 0x6a99340 [0x1582b48]>{contents = "type"} = <CFString 0x6a994d0 [0x1582b48]>{contents = "OAuthException"}
3 : <CFString 0x6a99470 [0x1582b48]>{contents = "message"} = <CFString 0x6a993d0 [0x1582b48]>{contents = "An active access token must be used to query information about the current user."}
6 : <CFString 0x6a52270 [0x1582b48]>{contents = "code"} = 2500
}
}
发出请求的代码如下所示(也许我需要在此处添加访问令牌?):
[facebook requestWithGraphPath:@"me" andDelegate:self];
现在我知道访问令牌是可以的,因为在init
方法中我调用了一个在必要时更新它的方法:
[facebook extendAccessTokenIfNeeded];
而且我还实现了委托方法extendAccessTokenIfNeeded
:
-(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt {
NSLog(@"token extended"); //This NSLog hasn't been called, so I know the extending access token method wasn't fired...
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
[defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
现在我在这里错过了什么?我需要将访问令牌添加到图形 API 请求吗?如果是这样,怎么做?
顺便说一句,我也知道,如果我向公共路径发出图形请求,它会完美运行。