Facebook API显示页面帖子中的完整尺寸图像?

时间:2014-11-25 19:38:56

标签: php json facebook facebook-graph-api

我正在使用Facebook API将帖子拉到我的网站,目前我无法从帖子中检索完整尺寸的图片,只能缩略图。对于作为视频的帖子,我获得了一个漂亮的大图像,但带图像的帖子只显示缩略图。

以下是一个示例回复:

[message] => She still likes to come home
                    [picture] => https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/s480x480/1509768_949952475034523_5777855144535809574_n.jpg?oh=296a9975752be40f24a0e32d613328aa&oe=54DCDB3A&__gda__=1426487880_adf80b362906423f8952c92925766989
                    [link] => https://www.facebook.com/photo.php?fbid=949952475034523&set=o.337363685362&type=1
                    [icon] => https://fbstatic-a.akamaihd.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif
                    [privacy] => stdClass Object
                        (
                            [value] => 
                        )

                    [type] => photo
                    [object_id] => 949952475034523
                    [application] => stdClass Object
                        (
                            [name] => Facebook for iPhone
                            [namespace] => fbiphone
                            [id] => 6628568379
                        )

                    [created_time] => 2014-11-25T18:43:41+0000
                    [updated_time] => 2014-11-25T18:43:41+0000

注意[picture]中的结果是一个小图像。

以下是我正在使用的代码:

<?php
function fetchUrl($url){

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);

$feedData = curl_exec($ch);
curl_close($ch); 

return $feedData;
}

$profile_id = "xxxxx";

//App Info, needed for Auth
$app_id = "xxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxx";

//Retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={$app_id}&client_secret={$app_secret}");

$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/feed?{$authToken}");

$feedarray = json_decode($json_object);
print_r($feedarray);
?>

是否有不同的编码方式可以让我检索完整尺寸的图像,或者有没有办法重新构建返回的URL以显示更大的图像?

谢谢。

1 个答案:

答案 0 :(得分:1)

Found this old post; you must already have figured it out; still, the answer is for you to restructure your url in order to get the "attachment":

https://graph.facebook.com/{$profile_id}/feed?access_token={$authToken}&fields=attachments

You will get a "src" which will have a larger image.