Ga Ye
Ga Ye

Reputation: 65

Facebook iOS SDK v4.0, get friends list

Seems like Facebook iOS SDK v4.0 has a lot of changes. I try to get a user's friends list after he login. I think it's something to do with FBSDKGraphRequestConnection but I'm not sure how it can be used.

Also, if I only want to get friends who are using my app, does facebook sdk support that?

Can anyone give some examples? Thanks!

Upvotes: 2

Views: 3441

Answers (3)

Pramuka Dias
Pramuka Dias

Reputation: 568

I used below code to get friend list

self.graphrequest = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/taggable_friends?limit=100"
                                                 parameters:@{ @"fields":@"id,name,picture.width(100).height(100)"}];
[self.graphrequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if (!error) {
        self.resultsArray = result[@"data"];
        [self.fbTableView reloadData];
        [self.fbTableView setHidden:NO];
    } else {
        NSLog(@"Picker loading error:%@",error.userInfo[FBSDKErrorLocalizedDescriptionKey]);
    }
}];

You can limit the number of friends using limit keyword.Ex: limit=100

Upvotes: 0

Celedonio Montes
Celedonio Montes

Reputation: 11

This shows how to handle the response:

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:nil]
 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
     if (!error)
     {
        NSArray * friendList = [result objectForKey:@"data"];
        for (NSDictionary * friend in friendList)
        {
            NSLog(@"Friend id: %@", friend[@"id"]);
            NSLog(@"Friend name: %@", friend[@"name"]);             
        }
    }
}];

Upvotes: 1

Ming Li
Ming Li

Reputation: 15662

FBSDKGraphRequest *friendsRequest = 
    [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends"
                                      parameters:parameters];
FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
[connection addRequest:friendsRequest
     completionHandler:^(FBSDKGraphRequestConnection *innerConnection, NSDictionary *result, NSError *error) {
         ...
     }];
// start the actual request
[connection start];

Upvotes: 4

Related Questions