Facebook Request Never Gets Executed

淺唱寂寞╮ 提交于 2019-12-11 01:23:26

问题


I am trying to get a user's Facebook Friends who also use the same app.

"Time to get other friends that use this app" always prints out

But neither the result, nor the error are printed

I checked the graph path with Facebook's Graph API explorer, and it worked, but it does not work with my app for some reason.

- (void)getFriendsForUser:(NSNotification *)notification {
    GGUser *theCurrentUser = [notification object];
    NSLog(@"Time to get other friends that use this app");
    [FBRequestConnection startWithGraphPath:@"me/friends?fields=id,name,installed,picture" parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        NSLog(@"result %@",result);
        NSLog(@"error - %@", error);            
    }];
}

Other FBRequests, like with a graph path of @"me", work, just not this one. What am I doing wrong? How do I fix this?


回答1:


It seems you are not passing the token that's why the request itself is not getting executed:

Do this:

FBRequest *facebookReq =  [FBRequest requestForGraphPath:@"me/friends?fields=id,name,installed,picture"];

[facebookReq setSession:FBSession.activeSession];

[facebookReq startWithCompletionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error) {
    NSLog(@"result %@",result);

    NSLog(@"error %@",error);

}];

Let me know if it doesn't work. :)

Cheers




回答2:


I think your issue is that you're putting request parameters into the path.

Try using just @"me/friends" as the path, and @{ @"fields", @"id,name,installed,picture" } as the parameters.




回答3:


The following code should do just fine. But make sure you are executing it on the main thread.

It looks like not every thread is usable for FBRequest. I am personally had issues starting requests from Core Data context's thread.

NSString* path = @"me/friends?fields=id,name,installed,picture";
FBRequest* req = [[FBRequest alloc] initWithSession:[FBSession activeSession]
                                          graphPath:path];
[req startWithCompletionHandler:^(FBRequestConnection* connection,
                                  NSDictionary<FBGraphObject>* result,
                                  NSError* error)
{
    NSLog(@"result %@",result);
    NSLog(@"error %@",error);
}


来源:https://stackoverflow.com/questions/18310102/facebook-request-never-gets-executed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!