图谱API:在页面Feed中检索图片尺寸

时间:2013-05-10 04:20:15

标签: facebook facebook-graph-api

我使用Graph API获取粉丝页面的墙贴。

我注意到Facebook iOS应用程序本身能够确定其占位符的确切比率。

enter image description here

http://developers.facebook.com/tools/explorer?method=GET&path=facebook%2Ffeed%3Ffields%3Dpicture

{
    "data": [
             {
             "picture": "http://photos-b.ak.fbcdn.net/hphotos-ak-frc1/247019_457846347622804_946521095_s.jpg",
             "id": "20531316728_10151883063741729",
             "created_time": "2013-05-02T16:57:25+0000"
             },
               :
               :
               :
             {
             "picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash4/223257_10151498310776729_930531604_s.jpg", 
             "id": "20531316728_10151498193061729", 
             "created_time": "2012-10-05T18:42:38+0000"
             }
             ], 
    "paging": {
        "previous": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&since=1367513845", 
        "next": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&until=1349462557"
    }
}

它不包含图片的信息。 API响应中的维度,我希望我的自定义客户端(如Facebook iOS应用程序)具有正确的占位符大小。

我尝试添加/facebook/feed?fields=picture,width,height,但在检索相应信息方面没有运气。

是否有可能从API本身检索图片的高度和宽度参数?

2 个答案:

答案 0 :(得分:1)

不,API不会根据来自/ page_id / feed或流表的帖子提交返回所有图片的尺寸。

我提到了所有因为,你能做的是:

SELECT post_id, created_time, actor_id, attachment, message FROM stream WHERE source_id=PAGE_ID AND created_time<now() LIMIT 50

如果帖子类型是照片: enter image description here

如果帖子类型是视频: enter image description here

如果帖子类型是链接以fbexternal开头(提取参数w和h): enter image description here

如果帖子类型是没有fbexternal(facebook照片)的链接,我们就会卡在这里!: enter image description here

代码原型:

if attachment:
    image_url = attachment.media[0].src
    if image_url:
        m = image_url.photo.images
        if m:
            if m.src == image_url:
                image_width = m.width
                image_height = m.height
        else: #no dimensions info
            if host by fbexternal:
                #extract parameter w and h from https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBhfbzbNudc_SE8&w=130&h=130&url=http%3A%2F%2F
                image_width = 130
                image_height = 130
             else:
                 Stuck here, very hard to get extract photo id based on this url, a lot of work!

总之,我强烈建议您在下载照片后获得图像宽度和高度。例如,PHP具有getimagesize功能,python具有Python Imaging Library(PIL)。

答案 1 :(得分:0)

我不确定是否有更简单的方法来获得所需的宽度和高度,但这是一种肯定但有点啰嗦的方式。

以您的示例为例,您在第一张图片“20531316728_10151883063741729”中看到的ID实际上并不是图片的ID。这是图片所在的帖子。

您可以做的是查询该postID

http://developers.facebook.com/tools/explorer?method=GET&path=20531316728_10151883063741729

然后它将曝光图片的object_id 457846347622804(做一个搜索,你会明白我的意思)。现在你查询该图片的ID,你将获得你的宽度和高度。

http://developers.facebook.com/tools/explorer?method=GET&path=457846347622804

从那时起,您应该能够获得所需的比例。

如果有人有一种优雅的方式来完成这项工作,我也很想知道。

相关问题