简体   繁体   English

Facebook 如何使用 Graph API 获取实际照片 URL?

[英]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_timenameid

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.

相关问题 如何使用 facebook 图 Z8A5DA52ED1264727D8AZ8A5DA52ED1264727D8AZ505 获得 Facebook 照片的来源 URL - How do you get a Facebook photo's source URL using the facebook graph api? 如何使用Facebook graph API获取照片共享的详细数据 - How to get photo share detailed data using Facebook graph API 如何使用图形api获取Facebook用户相册? - How to get Facebook user photo albums using graph api? 如何使用图形API获取Facebook照片的评论? - How to get comments of facebook photo using graph api? 使用Facebook graph API从帖子中获取照片 - Get photo from post using Facebook graph API 在给定照片ID的情况下获取照片URL:iOS的Facebook Graph API(快速) - Get Photo URL Given a Photo ID: Facebook Graph API for iOS (Swift) 如何通过GRAPH API获取Facebook照片隐私设置 - How to get Facebook photo privacy settings via GRAPH API 使用脸谱图api如果Feed类型是照片,如何获取大图片尺寸的新闻Feed? - Using facebook graph api how to get news feed with large picture size if the feed type is photo? 如何在 Android 上使用 Facebook Graph API 获取用户相册列表 - How to get a list of user photo albums using the Facebook Graph API on Android 如何使用Facebook Graph API获取用户上传的所有照片? - How can I get all the photo uploaded by user using Facebook Graph API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM