dpg76975 2014-11-25 19:38
浏览 63
已采纳

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

I am using the Facebook API to pull posts into my website and currently I am not able to retrieve the full-sized image from a post, only thumbnails. For posts which are videos, I get a nice large image, but posts with images only display the thumbnail image.

Here is an example response:

[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

Notice how the result in [picture] is a small image.

Here is the code I am using:

<?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);
?>

Is there a different way to code this that will allow me to retrieve the full-sized image, or is there a way to restructure the URL that is returned to display the larger image?

Thank you.

  • 写回答

1条回答 默认 最新

  • dongxianghui3709 2015-08-14 22:53
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗