【问题标题】:Get full sized picture from facebook graph API从 facebook graph API 获取全尺寸图片
【发布时间】:2015-03-13 13:14:02
【问题描述】:

我正在使用图形 api 端点 /PAGE_ID/posts 从 facebook 页面获取所有帖子。 现在我想要这些帖子中的全尺寸图片。返回对象的图片属性只为我提供了该图像的裁剪版本。

通过这些帖子中的对象 ID 和 API 端点 /OBJECT_ID/picture,我得到了图片的唯一小型、正常和专辑大小的版本。但是通过对 URL 稍作修改,我设法获得了完整尺寸的图像。

示例

此网址:
https://graph.facebook.com/10152843929471041/picture

重定向到此网址:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/s720x720/10838228_10152843929471041_5251228402651650719_n.jpg

我从该 URL 中删除了 720x720 以获取此 URL:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/s/10838228_10152843929471041_5251228402651650719_n.jpg

这终于是全尺寸的图像了。

我认为,我可以使用正则表达式模式来实现此修改。但现在是我的问题,如何在从原始 URL(第一个 URL)重定向后获取 URL。

有什么想法或更简单的解决方案吗?

【问题讨论】:

    标签: javascript regex facebook facebook-graph-api redirect


    【解决方案1】:

    这是获得更大图片的方法:

    /OBJECT-ID/picture?width=500&height=500
    

    或者:

    /OBJECT-ID/picture?type=large
    

    还可以看看这个帖子中的答案:Facebook Graph API : get larger pictures in one request

    编辑:由于这似乎不适用于对象 ID,您可以从该响应中获取图像:

    https://graph.facebook.com/10152843929471041
    

    注意“图像”数组。

    【讨论】:

    • 这不适用于使用对象 ID 获取的图片。我只能使用缩略图、普通和相册
    • 谢谢!你的编辑做到了。
    【解决方案2】:

    也可以请求photo 对象的images 集合,然后搜索最高分辨率条目

    documentation。代码:

    MyFacebookWrapper.getBestImage = function(photoId) {
        var deferred = new $.Deferred();
        var params = { fields: "images" };
    
        FB.api("/" + photoId, "get", params,
            function (response) {
                console.log("MyFacebookWrapper.getBestImage, response:");
                console.log(response);
    
                var images = _.sortBy(response.images, 'width');
                var best = _.last(images)
    
                deferred.resolve(best); 
            }
        );
    
        return deferred.promise();
    };
    

    用法:

    MyFacebookWrapper.getBestImage("photo Id ...").then(function(image) {
        console.log(image);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-07
      • 2014-06-24
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      相关资源
      最近更新 更多