GangstaGraham
GangstaGraham

Reputation: 9385

Facebook Request Never Gets Executed

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?

Upvotes: 2

Views: 241

Answers (3)

Bobrovsky
Bobrovsky

Reputation: 14246

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);
}

Upvotes: 0

Reno Jones
Reno Jones

Reputation: 1979

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

Upvotes: 2

Ming Li
Ming Li

Reputation: 15662

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.

Upvotes: 0

Related Questions