我和这篇文章几乎有同样的问题:iOS Facebook SDK: An active access token must be used to query information about the current user,但解决方案似乎对我不起作用。
在该方法的前面,我称之为:
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_photos",
@"user_status",
@"read_stream",
nil];
self.fb = [[FBSession alloc] initWithPermissions:permissions];
[self.fb openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error)
{
if(!error){
NSLog(@"Facebook Authorized");
}
if(error){
NSLog(@"Error in fb auth request: %@", error.localizedDescription);
}
}];
我成功地以用户访问权限登录。然后,我需要获取用户最近的帖子,所以我这样做:(FQL)
NSMutableArray *postIDArray = [[NSMutableArray alloc]init];
NSString *query = @"SELECT post_id FROM stream WHERE source_id = me() AND is_hidden = 0 ORDER BY created_time DESC LIMIT 10";
//this was the solution the other SO answer had.
[FBSession setActiveSession:self.fb];
// Set up the query parameter
NSDictionary *queryParam = @{ @"q": query };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:@"/fql"
parameters:queryParam
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else if(!error) {
NSLog(@"Result: %@", result);
NSDictionary *resultDict = (NSDictionary *)result;
NSArray *postArr = [resultDict objectForKey:@"data"];
for (FBGraphObject *friendObj in postArr) {
NSString *postIDString = [friendObj objectForKey:@"post_id"];
[postIDArray addObject:postIDString];
}
NSLog(@"postidarray array : %@", postIDArray);
//with post ids, loop through and use graph api to get the post details.
for (int i = 0; i <= postIDArray.count; i++) {
NSString *path = [NSString stringWithFormat:@"https://graph.facebook.com/me/%@",[postIDArray objectAtIndex:i] ];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:path]];
NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSDictionary *postDict = [result yajl_JSON];
NSLog(@"post %d contents: %@",i, postDict);
}
}
}];
}
我可以得到 post_ID 的罚款,但是当我尝试打电话时
https://graph.facebook.com/me/<my_post_id>
返回的数据是:
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
}
知道发生了什么吗?提前致谢。
编辑:我尝试使用
[FBRequestConnection startWithGraphPath:postIDString id result, NSError *error) {
if (error) {
NSLog(@"Error: %@", [error localizedDescription]);
} else if(!error) {
//do some parsing stuff
}
但我收到此错误:错误:无法完成操作。(com.facebook.sdk 错误 5。)