[英]Facebook how to get actual photo URL using Graph API?
It is possible to get the actual image url of a Facebook image using the Graph api??可以使用 Graph api 获取 Facebook 图像的实际图像 url?
For instance, for the below photo http://www.facebook.com/photo.php?fbid=357755307655174例如,对于下面的照片http://www.facebook.com/photo.php?fbid=357755307655174
the actual URL is https://fbcdn-sphotos-aa.akamaihd.net/hphotos-ak-ash4/252428_530045532341_5136_n.jpg实际网址是https://fbcdn-sphotos-aa.akamaihd.net/hphotos-ak-ash4/252428_530045532341_5136_n.jpg
Is there some graph api way to achieving this?有没有一些图形 API 方法来实现这一点?
By default, not all fields in a node or edge are returned when you make a query.默认情况下,当您进行查询时,并非节点或边中的所有字段都会返回。 You can choose the fields or edges that you want returned with the
fields
query parameter.您可以选择要使用fields
查询参数返回的字段或边。
That's why when you retrieve a photo, you may only get created_time
, name
and id
.这就是为什么当您检索照片时,您可能只会获得created_time
、 name
和id
。
source
field is deprecated in latest API (v2.8).最新的 API (v2.8) 中不推荐使用source
字段。 Use images
instead.改用images
。
So your query may look like this:因此,您的查询可能如下所示:
GET graph.facebook.com/{photo-id}?fields=images
Response should be like this:响应应该是这样的:
{
"images":[
{
"height":358,
"source":"https://scontent.xx.fbcdn.net/v/t1.0-9/15327427_585435148333529_xxxxxxxxxxxx_n.jpg?oh=xxxxxxxx&oe=xxxxxxxxx",
"width":518
},
{
"height":320,
"source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p320x320/15327427_xxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxx&oe=xxxx&__gda__=xxxxxxxxxxxx",
"width":463
},
{
"height":130,
"source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p130x130/15327427_xxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxxx&oe=xxx&__gda__=xxxxxxxxxxxxxxxxxx",
"width":188
},
{
"height":225,
"source":"https://fb-s-c-a.akamaihd.net/h-ak-xtl1/v/t1.0-0/p75x225/15327427_xxxxxxxxxxxxxxx_n.jpg?oh=xxxxxxxxxxxxxxxxx&oe=xxxxxxxxxxxxxxxxxx&__gda__=xxxxxxxxxxxxxxxxxx",
"width":325
}
],
"id":"585435148333529"
}
Is there some graph api way to achieving this?有没有一些图形 API 方法来实现这一点?
Therefore, you'd have to look at the source
field of the photo object:因此,您必须查看照片对象的source
字段:
source:来源:
The source image of the photo - currently this can have a maximum width or height of 720px, increasing to 960px on 1st March 2012照片的源图像 - 目前最大宽度或高度为 720 像素,2012 年 3 月 1 日增加到 960 像素
string representing a valid URL表示有效 URL 的字符串
That'll give you the original size the photo was uploaded for smaller images, or resized to max.这将为您提供照片为较小图像上传的原始尺寸,或调整为最大尺寸。 960px in each direction.每个方向 960 像素。
For even larger sizes, you'd have to check the images
field:对于更大的尺寸,您必须检查images
字段:
images:图片:
The 4 different stored representations of the photo照片的 4 种不同存储表示
array of objects, containing height, width, and source fields对象数组,包含高度、宽度和源字段
This “promises” to deliver much larger sizes (fe 2048×1417px) – but be aware, these entries will still deliver a smaller image if the original one wasn't as large as requested.这“承诺”提供更大的尺寸(fe 2048×1417px)——但请注意,如果原始图像没有要求的那么大,这些条目仍将提供更小的图像。
请求字段附件,您将在其中找到原始图像。
&fields=picture.type(large),attachments
There seems to be lack of documentation for this.似乎缺乏这方面的文档。 It can simple be achieved in this way.可以通过这种方式简单地实现。 In that url http://www.facebook.com/photo.php?fbid=357755307655174 , take out the id of the pic represented by fbid .In the above case it is 357755307655174 .在那个网址http://www.facebook.com/photo.php?fbid=357755307655174 中,取出fbid表示的图片的 id。在上面的例子中,它是357755307655174 。 Now do a graph api query, to this object https://graph.facebook.com/357755307655174 .现在对这个对象进行图形 API 查询https://graph.facebook.com/357755307655174 。 This will return a JSON with all the aspect ratio's present in their database and their actual URL's.这将返回一个 JSON,其中包含数据库中存在的所有纵横比及其实际 URL。 Each data field following the format每个数据字段遵循格式
{
"height": 1080,
"source": "https://scontent-a.xx.fbcdn.net/hphotos-xpf1/t31.0-8/10296099_566697856780203_6555830953677139074_o.jpg",
"width": 1980
}
Use the Graph Explorer to check once again the format of returned JSON data.The source is what you are looking for.使用 Graph Explorer 再次检查返回的 JSON 数据的格式。源就是您要查找的内容。
new GraphRequest(
facebookToken,
String.format("/%s/photos", idAlbum),
parameters,
HttpMethod.GET,
response -> {
try {
JSONArray photoArray = response.getJSONObject().getJSONArray("data");
photosAlbumAfterPagination = response.getJSONObject().getJSONObject("paging").getJSONObject("cursors").getString("after");
Gson gson = new Gson();
Type type = new TypeToken<List<FacebookPhotoResponse>>() {
}.getType();
List<FacebookPhotoResponse> list = gson.fromJson(photoArray.toString(), type);
} catch (JSONException e) {
e.printStackTrace();
}
}
).executeAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.