How to get the large picture from feed with graph api?

前端 未结 9 1622
灰色年华
灰色年华 2020-12-08 05:14

When loading the Facebook feeds from one page, if a picture exist in the feed, I want to display the large picture.

How can I get with the graph API ? T

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 05:35

    For high res image links from:

    • Link posts
    • Video posts
    • Photo posts

    I use the following:

    Note: The reason I give the _s -> _o hack precedence over the object_id/picture approach is because the object_id approach was not returning results for all images.

    var picture = result.picture;
    if (picture) {
        if (result.type === 'photo') {
            if (picture.indexOf('_s') !== -1) {
                console.log('CONVERTING');
                picture = picture.replace(/_s/, '_o');
            } else if (result.object_id) {
                picture = 'https://graph.facebook.com/' + result.object_id + '/picture?width=9999&height=9999';
            }
        } else {
            var qps = result.picture.split('&');
            for (var i = 0; i < qps.length; i++) {
                var qp = qps[i];
                var matches = qp.match(/(url=|src=)/gi);
                if (matches && matches.length > 0) picture = decodeURIComponent(qp.split(matches[0])[1]);
            }
        }
    }
    

提交回复
热议问题