简体   繁体   中英

How can I get profile picture (of friend)

I want to get user's friends profile picture, but I want the picture to be in type large.

Let's say that I'm ok with taggable_friends (a separated issue itself), so I get it like this:

Login + permissions:

    FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]];

    loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), (self.view.center.y - (loginView.frame.size.height / 2)));
    [self.view addSubview:loginView];

Now the taggable_friends :

FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me?fields=invitable_friends" parameters:nil HTTPMethod:@"GET"];
[friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                              NSDictionary* result,
                                              NSError *error) {
    NSArray* friends = [[result objectForKey:@"invitable_friends"] objectForKey:@"data"];
    NSLog(@"Found: %i friends", friends.count);
    for (NSDictionary<FBGraphUser>* friend in friends) {
        NSLog(@"friend.name %@", friend.name);
        NSLog(@"friend.objectID %@", friend.objectID);

    }

}];

Ok, so I have the objectID , how can I use it to get the user's large profile picture?

This isn't work for me:

https://graph.facebook.com/USER_ID/picture?type=large

Since the user ID is ~50 chars, and isn't 10-12 chars usually.

Any help please?!

Thanks in advance!

The id your using is not the true ID of the friend. That one acts as a placeholder as you do not have the access to their profile since they have never used your app. However, you can edit the url found in picture->data->url highlighted in bold in the sample url below to edit the size of their profile image.

https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/t1.0-1/ c0.0.100.100 / p100x100 /1470158_10201991701127909_302023572_n.jpg

c0.0.100.100 represents the size of the image container

p100x100 represents the size of the image itself

The two values should match to get the best effect. I did notice that you are unable to go past 200X200px for both the container and the image. Facebook might have a cap on the size settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM