How to get the bigger profile picture of a facebook page

前端 未结 4 1722
独厮守ぢ
独厮守ぢ 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条回答
  •  -上瘾入骨i
    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.

提交回复
热议问题