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
One line solution:
https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture
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!
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.
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.
精彩评论