PHP Facebook Graph API和完整或更大的发布图像 [英] PHP Facebook Graph API and full or larger size post images

查看:172
本文介绍了PHP Facebook Graph API和完整或更大的发布图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行了一些搜索,但没有任何内容出现或过时,不起作用

Did some searching but nothing is coming up or is old and doesn't work

我使用图形API来获取Facebook帖子并将它们格式化网站,工作的URL / curl / json的东西;但是,返回的图片默认为最小的130x130版本。我在foreach循环中为每个帖子添加了第二个json来抓取较大的图片网址,但这显着减慢了网页加载速度。

I'm using the graph api to get facebook posts and formatting them on my site, the URL/curl/json thing which is working; however, the picture returned defaults to the smallest 130x130 version. I added in a second json inside the foreach loop for each post to grab the larger image URL but this slows down the page load significantly.

有帖子的参数将抓取更大的720x720图像URl,而不是默认拉的微小的。我尝试了fields = full_picture用于第二个(在循环中),但它不工作。

Is there a parameter for the posts that will grab the larger 720x720 image URl instead of the tiny one pulled by default. I tried the fields=full_picture used for the second (in loop) one but it doesn't work.

还尝试使用file_get_contents()函数代替cURL解决方案但没有明显的速度差异

Also tried using the file_get_contents() function instead of the cURL solution but there was no noticeable speed difference

我也尝试过一个字符串替换的初始数组的图片数据,但Facebook添加那些oh =和oe = tokens

I also tried just doing a string replace to the picture data of the initial array but facebook adds those oh= and oe= tokens to their images URLs now so that trick doesn't work either.

$limit = 20;
//App Info, needed for Auth
$app_id = "app id removed :)";
$app_secret = "seceret code removed :)";

$url = 'https://graph.facebook.com/'.$profile_id.'/posts?limit='.$limit.'&access_token='.$app_id.'|'.$app_secret;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
$json = json_decode($data, true);

foreach($json[data] as $child) {
    $thisDate = $child['created_time'];
    $url='https://graph.facebook.com/' . $child['id'] . '?fields=full_picture&access_token='.$app_id.'|'.$app_secret;
    /*
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    $pic = json_decode($data, true);
    */
    $pic = json_decode(file_get_contents($url),true);
}

curl_close($ch);

此解决方案可以工作并提供更大的图片,但由于额外的cURL只会减慢网页加载速度

This solution does work and provides the larger images but just slows down the page load due to the extra cURL call inside the loop.

谢谢

推荐答案

在一个请求中使用 fields 参数:

You can get that data in one request, by using the fields parameter:

/me/posts?fields=message,full_picture

(如果您想要更多其他字段,还必须列出。)

(If you want more additional fields, you have to list them as well.)

这篇关于PHP Facebook Graph API和完整或更大的发布图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆