How to get the bigger profile picture of a facebook page

前端 未结 4 1706
独厮守ぢ
独厮守ぢ 2020-12-28 17:39

I am getting an image from facebook by the URL: http://external.ak.fbcdn.net/safe_image.php?d=d282e1e7c86c9270232f97ddc737df39&w=90&h=90&url=http%3A%2F%2Fi52.tin

相关标签:
4条回答
  • 2020-12-28 17:59

    If you want to get a larger picture you can just set the height and width you want like this:

    http://graph.facebook.com/[page id/profile id]/picture?width=[number]&height=[number]
    

    More info and examples here: Pictures - Facebook Developers

    0 讨论(0)
  • 2020-12-28 18:02

    Generally if you want to collect the profile pic of a user or page, the format for the icon size picture is:

    http://graph.facebook.com/[page id/profile id]/picture
    

    and for the large picture:

    http://graph.facebook.com/[page id/profile id]/picture?type=large
    

    EDIT Points to note: If the image stored on the facebook servers is less than the 200*200 dimensions, you would get the image as the highest resolution avaiable eg: 128*160. Either you can resize it using the GD library.

    AND ONE MORE THING

    Facebook supports 200*600px as the highest resolution for the profile pic. It will resize an image to fit into these dimensions by maintaining the aspect ratio.

    *UPDATE as on 19th Feb, 2017 *

    We need to use this new URL formation to get a desired profile image.

    http://graph.facebook.com/{profile_id}/picture?width={number‌​}&height={number}
    

    [Thank you https://stackoverflow.com/users/2829128/vay]

    0 讨论(0)
  • 2020-12-28 18:09

    YES, there is a way to get the original (most of time bigger) profile picture of a facebook page.

    Actually the answer is already in the question. The original image url is already embedded in the save_image url. In your case it is "url=http%3A%2F%2Fi52.tinypic.com%2F2q0ixzl.jpg” which means "http://i52.tinypic.com/2q0ixzl.jpg"

    In my case, the page for London is

    https://www.facebook.com/pages/London-United-Kingdom/106078429431815?fref=ts
    

    I can easily get its fb object id by search keyword London. I have tried to use width and height parameter. They work with user profile picture or user shared picture but can’t work with public pages profile picture.

    https://graph.facebook.com/106078429431815/picture?width=300&height=300  // can’t work
    

    The largest picture I can get it by following url which is only 180x77

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

    But I can get safe_image.php url by using fb graph api, and the original image url is also inside the parameters' url section

    "url": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCrtKykRotXBuaS&w=180&h=540&url=http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2Farchive%2F2%2F21%2F20141005220235%2521City_of_London_skyline_at_dusk.jpg%2F720px-City_of_London_skyline_at_dusk.jpg&fallback=hub_city&prefix=d"
    

    Here is code I used.

    [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@/picture?redirect=false&type=large",[firstCityPage objectForKey:@"id"]]
                        completionHandler:^(
                                            FBRequestConnection *connection,
                                            id result,
                                            NSError *error
                                            ) {
    
                            NSString *profileImgUrl = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", [firstCityPage objectForKey:@"id"]];
    
                            if (error==nil) {
                                NSString *fbSaveImgUrl = [[(NSDictionary*)result objectForKey:@"data"] objectForKey:@"url"];
    
                                NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:[NSURL URLWithString:fbSaveImgUrl]
                                                                            resolvingAgainstBaseURL:NO];
    
                                for (NSURLQueryItem *queryItem in urlComponents.queryItems) {
                                    if ([queryItem.name isEqualToString:@"url"]) {
                                        profileImgUrl = queryItem.value;
                                        break;
                                    }
                                }
    
                            } else {
                                NSLog(@"%@",[error description]);
                            }
    
                            NSLog(@"url: %@", profileImgUrl);
    
                            ...
                        }];
    

    BUT, there are risks.

    1. No guarantee the external image url will be validate.

    2. Facebook may remove the explicit external url in the safe_image url or hide the safe_image url from developer in future.

    Use it at your own risk.

    0 讨论(0)
  • 2020-12-28 18:11

    this will also work

    picture.type(large)

    example

     if ([FBSDKAccessToken currentAccessToken]) {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"picture.type(large),name, email"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error) {
                 NSLog(@"fetched user:%@", result);
                 NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                 data=result;
    
    
                 fbId.text=[data valueForKey:@"id"];
                 userName.text=[data valueForKey:@"name"];
                 _emailFB.text=[data valueForKey:@"email"];
    
    
    
                 NSDictionary *dictionary = (NSDictionary *)result;
    
                 NSDictionary *data3 = [dictionary objectForKey:@"picture"];
                 NSDictionary *data2 = [data3 objectForKey:@"data"];
                 NSString *photoUrl = (NSString *)[data2 objectForKey:@"url"];
    
                 NSLog(@"Photo : %@",photoUrl);
    
    
             }
         }];
    }
    

    }

    0 讨论(0)
提交回复
热议问题