javascript 获取更高分辨率的 Facebook 个人资料图片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9023109/
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-10-26 05:20:54  来源:igfitidea点击:

Get Facebook Profile Picture in higher resolution

javascriptfacebookfacebook-graph-api

提问by elauria

I was looking for the best way to get a user profile picture with the Facebook Graph API.

我一直在寻找使用 Facebook Graph API 获取用户个人资料图片的最佳方法。

Looking through the documentation, I've found this:

查看文档,我发现了这一点:

You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), and large (about 200 pixels wide, variable height)

您可以使用 type 参数指定所需的图片大小,它应该是正方形 (50x50)、小(50 像素宽、可变高度)、普通(100 像素宽、可变高度)和大(约 200 像素宽)之一, 可变高度)

My question is: Is there any way to get the profile picture on a higher resolution than 200px?

我的问题是:有没有办法以高于 200px 的分辨率获取个人资料图片?

I've recently found this solution, but I don't know how can I check if the user has the album in another language:

我最近找到了这个解决方案,但我不知道如何检查用户是否有另一种语言的专辑:

FB.api('/me/albums', function (response)
  {
    for (album in response.data)
    {
      // Find the Profile Picture album
      if (response.data[album].name == "Profile Pictures")
      {
         // Get a list of all photos in that album.
         FB.api(response.data[album].id + "/photos", function(response)
           {
             // The image link
             image = response.data[0].images[0].source;
           });
      }
    }
  });

回答by DMCS

This is straight from the documentation

这是直接来自文档

You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), and large (about 200 pixels wide, variable height):

http://graph.facebook.com/{ID}/picture?type=large

您可以使用 type 参数指定所需的图片大小,它应该是正方形 (50x50)、小(50 像素宽、可变高度)、普通(100 像素宽、可变高度)和大(约 200 像素宽)之一,可变高度):

http://graph.facebook.com/{ID}/picture?type=large

Now, there's nothing stopping you from calling into the graph to get larger sizes, but you have to have a valid user access token to do so.

现在,没有什么可以阻止您调用图表以获得更大的尺寸,但您必须拥有有效的用户访问令牌才能这样做。

回答by Mantas

回答by seantomburke

You can get the full quality image by using the Facebook JavaScript API:

您可以使用Facebook JavaScript API获得完整质量的图像:

FB.api('/{ID}?fields=picture.height(2048)', function(response){
   $("#profile_pic").attr("src",response.picture.data.url);
});

Assuming you have a

假设你有一个

<img id="profile_pic" src=""/> 

Somewhere in the body

身体某处

回答by CENT1PEDE

Am doing.

正在做。

FB.api('/'+id+'/picture?type=large&width=300&height=300', function(response){
    if(response && !response.error){
        // do your stuff.
    }
})

You can define the widthand heightto any value that suits you. You will see the additional options on their documentation.

您可以将width和定义为height适合您的任何值。您将在他们的文档中看到其他选项。