最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get full sized picture from facebook graph API - Stack Overflow

programmeradmin1浏览0评论

I'm using the graph api endpoint /PAGE_ID/posts to get all posts from a facebook page. Now I want the full sized image from these posts. The picture property of the returned objects gives me only a cropped version of that image.

With the object id from these posts and the API endpoint /OBJECT_ID/picture I get the only the small, normal and album sized version of the picture. But with a little modification to the URL I managed to get the full sized image.

Example

This URL:

redirects to this URL:
.0-8/s720x720/10838228_10152843929471041_5251228402651650719_n.jpg

I removed the 720x720 from that URL to get this URL:
.0-8/s/10838228_10152843929471041_5251228402651650719_n.jpg

which is finally the full sized image.

I think, that I can achieve this modification with a regex pattern. But now is my question, how I can get the URL after the redirect from the original URL (the first one).

Any ideas or simpler solutions?

I'm using the graph api endpoint /PAGE_ID/posts to get all posts from a facebook page. Now I want the full sized image from these posts. The picture property of the returned objects gives me only a cropped version of that image.

With the object id from these posts and the API endpoint /OBJECT_ID/picture I get the only the small, normal and album sized version of the picture. But with a little modification to the URL I managed to get the full sized image.

Example

This URL:
https://graph.facebook.com/10152843929471041/picture

redirects to this URL:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/s720x720/10838228_10152843929471041_5251228402651650719_n.jpg

I removed the 720x720 from that URL to get this URL:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xpa1/t31.0-8/s/10838228_10152843929471041_5251228402651650719_n.jpg

which is finally the full sized image.

I think, that I can achieve this modification with a regex pattern. But now is my question, how I can get the URL after the redirect from the original URL (the first one).

Any ideas or simpler solutions?

Share Improve this question asked Jan 15, 2015 at 7:18 Simon KnittelSimon Knittel 1,8513 gold badges16 silver badges24 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 14

This is how you can get larger pictures:

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

Or:

/OBJECT-ID/picture?type=large

Also take a look at answer in this thread: Facebook Graph API : get larger pictures in one request

Edit: As this does not seem to work with Object IDs, you can just grab the image from this response:

https://graph.facebook.com/10152843929471041

Look out for the "images" array.

One can also request the images collection of a photo object, then search for the highest resolution entry.

See documentation. Code:

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();
};

Usage:

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

评论列表(0)

  1. 暂无评论