jkigel
jkigel

Reputation: 1592

Facebook API for iOS, Getting friends' profile pictures

I would like to know how I can fetch friends' profile picture and display them with the Facebook API for iOS

Thanks

Upvotes: 21

Views: 14772

Answers (4)

jjjjjjjj
jjjjjjjj

Reputation: 4493

for iOS users looking for this, here is what helped me out (using version 5 of the graph, June 2016):

- (void)getUsersFaceBookFriends {
NSDictionary *params = @{@"fields": @"name, id, picture"};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:params HTTPMethod:@"GET"];

 [request 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"]);
            NSLog(@"Friend picture: %@", friend[@"picture"]);
        }
    }
 }];
}

this code will get the user's Facebook friends who are also using the app, along with their name, id, and profile photo url.

Upvotes: 0

Khurram Ali
Khurram Ali

Reputation: 835

If you use Three20, you can try this extension:

https://github.com/RIKSOF/three20/tree/development/src/extThree20Facebook

It allows you to use all Graph API features with just a few line of code.

Upvotes: 0

darki699
darki699

Reputation: 441

One line solution:

https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture

Upvotes: 43

donkim
donkim

Reputation: 13137

You can get a list of your friends at this endpoint: https://graph.facebook.com/me/friends. Then, you can get a friend's profile picture at this endpoint: https://graph.facebook.com/[profile_id]/picture.

Be sure to use this SDK: https://github.com/facebook/facebook-iphone-sdk

Hope this helps!

Upvotes: 28

Related Questions