Getting username and profile picture from Facebook iOS 7
This is the simplest way I've found to get the user's profile picture.
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) { if (error) { // Handle error } else { NSString *userName = [FBuser name]; NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]]; } }];
Other query parameters that can be used are:
- type: small, normal, large, square
- width: < value >
- height: < value >
- Use both width and height to get a cropped, aspect fill image
if ([FBSDKAccessToken currentAccessToken]) { [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{ @"fields" : @"id,name,picture.width(100).height(100)"}]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSString *nameOfLoginUser = [result valueForKey:@"name"]; NSString *imageStringOfLoginUser = [[[result valueForKey:@"picture"] valueForKey:@"data"] valueForKey:@"url"]; NSURL *url = [[NSURL alloc] initWithURL: imageStringOfLoginUser]; [self.imageView setImageWithURL:url placeholderImage: nil]; } }];}
Make the following Graph request:
/me?fields=name,picture.width(720).height(720){url}
And you get really large and cool profile picture:
{ "id": "459237440909381", "name": "Victor Mishin", "picture": { "data": { "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/t31.0-1/c628.148.1164.1164/s720x720/882111_142093815957080_669659725_o.jpg" } }}
P.S. /me?fields=picture.type(large)
doesn't do it for me.