Facebook Graph API:在一个请求中获取更大的图片

Mar*_*tin 84 facebook facebook-graph-api

我目前正在使用Graph API Explorer进行一些测试.这是一个很好的工具.

我想获取用户的朋友列表,包括朋友的姓名,ID和图片.所以我键入:

https://graph.facebook.com/me/friends?fields=id,picture,name
Run Code Online (Sandbox Code Playgroud)

但是图片只有50x50,我希望在这个请求中有一个更大的图片.

可能吗 ?

tha*_*smt 192

如Facebook上的此错误所述,您现在还可以通过新的API" 字段扩展 "语法请求特定的图像大小.

像这样:

https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)
Run Code Online (Sandbox Code Playgroud)

  • 确实.fields = picture.width(640)甚至更好. (24认同)
  • 请参阅2. field = full_picture,2.x查询的附件 (13认同)
  • 似乎Facebook Graph API改变了他们的api.当我尝试使用你的建议时,Facebook回应"子画面不受图片支持". (6认同)
  • 随着新的Facebook更改,无法获得更大的图像.有人提示吗? (3认同)
  • 收到错误:{"error":{"message":"不支持的get请求.请阅读https://developers.facebook.com/docs/graph-api上的Graph API文档","type":"GraphMethodException", "代码":100}} (2认同)

lus*_*chn 76

让所有朋友(当然也正在使用App)的正确图片尺寸的最佳方法是使用字段扩展,使用其中一个尺寸标签(方形,小尺寸,普通尺寸,大尺寸):

/me/friends?fields=picture.type(large)
Run Code Online (Sandbox Code Playgroud)

(编辑:这不再起作用了)

...或者您可以指定宽度/高度:

me/friends?fields=picture.width(100).height(100)
Run Code Online (Sandbox Code Playgroud)

顺便说一下,你也可以这样写:

me?fields=friends{picture.type(large)}
Run Code Online (Sandbox Code Playgroud)

  • 不再有效,但是full_picture,附件现在确实给出了正确的字段...... (6认同)

gul*_*yuz 66

你不需要拉"图片"属性.有更便捷的方式,你唯一需要的是userid,见下面的例子;

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

ps类型定义所需的大小

请注意,使用具有基本权限的令牌,/ me/friends将返回仅具有id + name属性的朋友列表

  • 呃,"在一个请求中"呢? (25认同)
  • 你也可以使用full_picture instat of picture. (4认同)

Jul*_*ann 33

将字段数组更改id,name,pictureid,name,picture.type(large)

https://graph.facebook.com/v2.8/me?fields=id,name,picture.type(large)&access_token=<the_token>
Run Code Online (Sandbox Code Playgroud)

结果:

{
   "id": "130716224073524",
   "name": "Julian Mann",
   "picture": {
      "data": {
         "is_silhouette": false,
         "url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15032818_133926070419206_3681208703790460208_n.jpg?oh=a288898d87420cdc7ed8db5602bbb520&oe=58CB5D16"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

  • 200 x 200大怎么样? (6认同)

Agu*_*ndo 28

您可以设置图片的大小(以像素为单位),如下所示:

https://graph.facebook.com/v2.8/me?fields=id,name,picture.width(500).height(500)
Run Code Online (Sandbox Code Playgroud)

以类似的方式,type可以使用参数

{user-id}/?fields=name,picture.type(large)
Run Code Online (Sandbox Code Playgroud)

文档中

type enum {small,normal,album,large,square}


Jon*_*ark 20

我广泛研究了Graph API Explorer,最后找到了full_picture

https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture
Run Code Online (Sandbox Code Playgroud)

PS我注意到full_picture不会总是提供我想要的全尺寸图像.'附件'确实如此

https://graph.facebook.com/v2.2/$id/posts?fields=picture,full_picture,attachments
Run Code Online (Sandbox Code Playgroud)


Swa*_*rks 19

您也可以根据高度或宽度尝试获取图像

https://graph.facebook.com/user_id/picture?height=

要么

https://graph.facebook.com/user_id/picture?width=

默认情况下,这些值只需要提供int值

  • 不工作.https://graph.facebook.com/2418855928223730/picture?width=130 (2认同)

Mar*_*tin 9

嗯......我想我找到了解决方案.

事实上,在可以只是请求

https://graph.facebook.com/me/friends?fields=id,name
Run Code Online (Sandbox Code Playgroud)

根据http://developers.facebook.com/docs/reference/api/("图片"部分),可以使用用户ID构建个人资料照片的网址

例如,假设用户ID在$ id中:

"http://graph.facebook.com/$id/picture?type=square"
"http://graph.facebook.com/$id/picture?type=small"
"http://graph.facebook.com/$id/picture?type=normal"
"http://graph.facebook.com/$id/picture?type=large"
Run Code Online (Sandbox Code Playgroud)

但它不是最终的图像URL,所以如果有人有更好的解决方案,我会很高兴知道:)


Ale*_*sin 5

您可以在 Facebook 图形 API 的请求中指定width& :heighthttp://graph.facebook.com/user_id/picture?width=500&height=500