我正在尝试将 Facebook 与我的 iOS 应用程序集成,但遇到了这个障碍。
当我第一次运行此代码时,它运行良好,但似乎 facebook 缓存中的某些内容导致了此错误:“必须使用活动访问令牌来查询有关当前用户的信息。”
我使用这两个函数来尝试上传照片:
+(BOOL)logInAndPostImage:(UIImage*)image andMessage:(NSString*)message {
NSArray *permissions = [NSArray arrayWithObjects:@"publish_stream", nil];
[FBSession.activeSession closeAndClearTokenInformation];
return [FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
if(error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Problem connecting with Facebook" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
} else {
[self postImage:image andMessage:message];
}
}];
}
+(void)postImage:(UIImage*)image andMessage:(NSString*)message
{
NSLog(@" Access Token Description: %@",[[FBSession activeSession] accessToken].description);
[FBRequestConnection startForUploadPhoto:image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
[[[UIAlertView alloc] initWithTitle:@"Result"
message:@"Your update has been posted to Facebook!"
delegate:self
cancelButtonTitle:@"Sweet!"
otherButtonTitles:nil] show];
} else {
[[[UIAlertView alloc] initWithTitle:@"Error"
message:@"Yikes! Facebook had an error. Please try again!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil] show];
NSLog(@"%@", error);
}
}];
}
当我查询活动令牌描述的描述时,它实际上是空的。所以我猜虽然FBSession openActiveSessionWithPublishPermissions:defaultAudience:allowLoginUI:completionHandler:
没有返回错误,但我没有生成令牌?
关于如何进一步调试此错误的任何建议?我已经按照 Facebook 开发者页面列出的所有附加设置进行了操作。