ios 如何获得更大的 facebook 页面的个人资料图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6176775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:09:05  来源:igfitidea点击:

How to get the bigger profile picture of a facebook page

iphoneobjective-ciosfacebookurl

提问by PJR

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.tinypic.com%2F2q0ixzl.jpg

我通过以下 URL 从 facebook 获取图像:http: //external.ak.fbcdn.net/safe_image.php?d=d282e1e7c86c9270232f97ddc737df39&w=90&h=90&url= http%3A%2F%2Fi52.tinypic.com%2F

Now, I want a bigger version, like 200 by 200. Is there a URL for that? If not, how can I convert this image to a larger size?

现在,我想要一个更大的版本,比如 200 x 200。有那个 URL 吗?如果没有,如何将此图像转换为更大的尺寸?

回答by Sujit Agarwal

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

EDITPoints 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.

编辑要点注意:如果存储在 facebook 服务器上的图像小于 200*200 尺寸,您将获得可用的最高分辨率图像,例如:128*160。您可以使用 GD 库调整其大小。

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.

Facebook 支持 200*600px 作为个人资料图片的最高分辨率。它将通过保持纵横比来调整图像大小以适应这些尺寸。

*UPDATE as on 19th Feb, 2017 *

*更新于 2017 年 2 月 19 日 *

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

我们需要使用这个新的 URL 格式来获取所需的个人资料图片。

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

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

[谢谢https://stackoverflow.com/users/2829128/vay]

回答by Kobulniczky Csongor

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

更多信息和示例在这里:图片 - Facebook 开发者

回答by Subhojit Mandal

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);


         }
     }];
}

}

}

回答by River2202

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

是的,有一种方法可以获取 Facebook 页面的原始(大多数情况下更大)个人资料图片。

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"

其实答案已经在问题中了。原始图像 url 已嵌入 save_image url 中。在您的情况下,它是“url=http%3A%2F%2Fi52.tinypic.com%2F2q0ixzl.jpg”,意思是“ 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.

我可以通过搜索关键字 London 轻松获取其 fb 对象 ID。我尝试使用宽度和高度参数。它们与用户个人资料图片或用户共享图片一起使用,但不能与公共页面个人资料图片一起使用。

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

我可以通过以下网址获得最大的图片,该图片仅为 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

但是我可以通过fb graph api获取safe_image.php url,原始图片url也在参数的url部分

"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.

  1. 不保证外部图像 url 将被验证。

  2. Facebook 可能会在未来删除 safe_image url 中的显式外部 url 或向开发者隐藏 safe_image url。

Use it at your own risk.

需要您自担风险使用它。