按ID获取用户个人资料照片

116 facebook facebook-graph-api

我现在正在开发一个主要基于facebook graph api的Web应用程序.我持有一些关于用户的数据 - 实际上是可用的公共数据 - 例如名称和ID.我也知道个人资料图片是公共数据的一部分,我想知道如何才能通过使用他的ID获得用户个人资料图片的直接链接?

提前致谢

Zac*_*tel 278

http://graph.facebook.com/"+ facebookId +"/ picture?type = square例如:http://graph.facebook.com/67563683055/picture?type = square

除了"square"之外还有更多尺寸.查看文档.

  • 对于想要链接到文档的人:https://developers.facebook.com/docs/graph-api/reference/user/picture/ (28认同)
  • 最好查看文档,因为它们还具有所有其他选项.例如,如果你想要一个大的方形图像(因为方形默认值很小),你必须使用`https://graph.facebook.com/ {facebookId}/picture?type = large&width = 720&height = 720`. (27认同)
  • 有没有办法只查询图片网址而不是图片本身?如果可能,希望不通过服务器在前端上传图像 (2认同)
  • 使用redirect = 0来获取JSON描述(包括url)而不是图像本身 (2认同)

Dul*_*iri 120

您可以使用以下网址来获取不同大小的个人资料图片.请确保将Facebook ID添加到网址.

大尺寸照片 https://graph.facebook.com/ {facebookId}/picture?type = large

中等大小的照片 https://graph.facebook.com/ {facebookId}/picture?type = normal

小尺寸照片 https://graph.facebook.com/ {facebookId}/picture?type = small

方形照片 https://graph.facebook.com/ {facebookId}/picture?type = square

  • 这就是我能够发现自己的FacebookId的方式:https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname&version=v2.5 (2认同)

rey*_*ard 36

获得最大尺寸的图像

https://graph.facebook.com/{userID}?fields=picture.width(720).height(720) 
Run Code Online (Sandbox Code Playgroud)

或者你需要的任何其他尺寸.根据经验,type = large不是您可以获得的最大结果.

  • 这不需要访问令牌(现在)吗? (2认同)

Sad*_*Ali 17

这将是有用的链接:

http://graph.facebook.com/893914824028397/picture?type=large&redirect=true&width=500&height=500

您可以根据需要设置高度和宽度

893914824028397facebookid


Igy*_*Igy 13

实际上Graph API文档的首页上.

  • /OBJECT_ID/picture 返回重定向到对象的图片(在这种情况下是用户)
  • /OBJECT_ID/?fields=picture 返回图片的URL

例子:

<img src="https://graph.facebook.com/4/picture"/> 使用HTTP 301重定向到Zuck的个人资料图片

https://graph.facebook.com/4?fields=picture 返回URL本身

  • *否*,它不在Graph API文档的首页上.你最好避免SO上的时间限制语句.你知道......那些日子变化很快...... (3认同)

Edd*_*dyG 10

2020 年 9 月更新

Facebook 有新的要求变更:所有基于 UID 的查询都需要访问令牌

因此,您必须将您的应用访问令牌添加到 url:

https://graph.facebook.com/{profile_id}/picture?type=large&access_token={app_access_token}
Run Code Online (Sandbox Code Playgroud)

要让您app_access_token使用以下网址:

https://graph.facebook.com/oauth/access_token?client_id={your-app-id}&client_secret={your-app-secret}&grant_type=client_credentials
Run Code Online (Sandbox Code Playgroud)

您可以在 Facebook 开发者的 Facebook 应用程序的基本设置中找到your-app-idyour-app-secret


Nor*_*ruz 6

在这里,此API可让您轻松获取fb,google和twitter个人资料照片

https://www.avatars.io/

当为Twitter,Facebook,Instagram和Gravatar等各种社交网络提供用户名时,该API会返回个人资料图片。它具有适用于iOS,Android,Ruby,Node,PHP,Python和JavaScript的库。