【发布时间】:2014-09-20 17:28:14
【问题描述】:
您好,我正在完成一个网站的 facebook 提要,并注意到 SDK 返回的图像质量非常低。
过去我做过类似 str 将 s.jpg 替换为 n.jpg 或 o.jpg 的操作。我知道这些修复。它们在这种情况下不起作用。
此外,过去我也抓取了 s130x130 段并将其更改为调整大小。同样,这在我的情况下不起作用。
我在 facebook 提要中返回的网址具有我以前从未见过的格式。
https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/s130x130/10426213_842375602447918_6490185390368658086_n.jpg?oh=a2db80558f6e5075b1b5c0cfbe9f6d09&oe=5487ACF5&__gda__=1418998035_89dfe352a7b600215d335f6317ed621d
它们具有所有常见的元素,但是,它们也具有 ?oh&oe&gda。这显然是 GET 数据的形式。这些元素似乎必须存在,并且是实例的正确元素。似乎是这些东西阻止了重新调整大小。让我解释一下:
我知道一张图片有多种尺寸,因为我可以在
http://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-xpa1/v/t1.0-9/s720x720/10426213_842375602447918_6490185390368658086_n.jpg?oh=a23ee08c91265d6396c3f19e9dee5a22&oe=5493DB4F&__gda__=1422978473_f94a2eba685581687bc048a255c26ca4
我的第一个想法是尝试像这样抓取图像
或
但是,这会返回错误 “处理您的请求时发生错误。 参考#50.e4bf6d8.1411232880.1d669acb"
如果我尝试编辑之前的链接(标记为代码)并更改大小,我也会得到相同的响应。
那么最终,如何从 facebook 提要重新调整大小或获得更大的图像大小?或者我如何修改我必须在 250 或 500 像素的球场上获得的东西?似乎哦,gdp 和 oe 以某种方式进行身份验证,我真的不知道如何生成正确的答案。在我看来,人们似乎只是在尝试重新调整个人资料图片的大小,而不是内容。
下面是我的完整代码
<?php
// include the facebook sdk
require_once('resources/facebook-php-sdk-master/src/facebook.php');
// connect to app
$config = array();
$config['appId'] = 'APP_ID';
$config['secret'] = 'APP_SECRET';
$config['fileUpload'] = false; // optional
// instantiate
$facebook = new Facebook($config);
// set page id
$pageid = "PAGE_ID";
// now we can access various parts of the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
//get page picture
$page_picture = 'http://graph.facebook.com/' . $pageid . "/picture?app_id=" . $config['appId'];
if(isset($fb_post_limit)){
$numb_of_posts = $fb_post_limit;
}else{
$numb_of_posts = 7;
}
// now we can access various parts of the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
function check_picture($post){
// if there is a picture post it
if(!empty($post['picture'])){
echo '<div class="row">';
echo '<img src="' . $post['picture'] . '" class="facebook-img col-xs-12"/>';
echo '</div>';
}
}
?>
<?php
echo "<div class=\"fb-feed\">";
// set counter to 0, because we only want to display $numb posts
$i = 0;
foreach($pagefeed['data'] as $post) {
if($post['from']['name'] == 'PAGE NAME'){
if ($post['type'] == 'status' || $post['type'] == 'link' || $post['type'] == 'photo') {
// open up an fb-update div
echo "<div class=\"fb-update col-xs-12\">";
$ids = explode('_', $post['id']);
// check if post type is a status
if ($post['type'] == 'status') {
if(!$post['story'] == 'PAGE NAME commented on a post.' ){
check_picture($post);
if (empty($post['story']) === false) {
echo '<img src="' . $page_picture . '" class="fb-profile" >' ;
echo "<p class=\"fb-message\" >" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
echo '<img src="' . $page_picture . '" class="fb-profile" >';
echo "<p class=\"fb-message\">" . $post['message'] . "</p>";
}
// post the time
echo "<h5 class=\"fb-date\">Status updated: " . date("jS M, Y", (strtotime($post['created_time']))) . "</h5>";
echo '<a class="facebook link btn btn-default btn-lrg" href="http://www.facebook.com/' . $pageid . '/posts/' . $ids[1] . '" >View Post</a>';
} else {
$i--;
}
}
// check if post type is a link
if ($post['type'] == 'link') {
echo '<img src="' . $page_picture . '" class="fb-profile" >';
if(!empty($post['message'])){ echo "<p class=\"fb-message\">" . str_replace($post['link'], '', $post['message']) . "</p>";}
echo "<h5 class=\"fb-date\">Link posted on: " . date("jS M, Y", (strtotime($post['created_time']))) . "</h5>";
check_picture($post);
echo '<p class="fb-link-desc"' . $post['name'] . '</p>';
if (empty($post['story']) === false) {
echo "<p class=\"fb-message\" >" . $post['story'] . "</p>";
}
echo "<p ><a href=\"" . $post['link'] . "\" target=\"_blank\">" . $post['link'] . "</a></p>";
echo '<a class="fb-link btn btn-default btn-lrg" href="http://www.facebook.com/' . $pageid . '/posts/' . $ids[1] . '" >View Post</a>';
}
// check if post type is a photo
if ($post['type'] == 'photo') {echo '<img src="' . $page_picture . '" class="fb-profile" >';
check_picture($post);
echo "<h5 class=\"fb-date\">Photo posted on: " . date("jS M, Y", (strtotime($post['created_time']))) . "</h5>";
if (empty($post['story']) === false) {
echo "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
echo "<p>" . $post['message'] . "</p>";
}
echo '<a class="facebook link btn btn-default btn-lrg" href="http://www.facebook.com/' . $pageid . '/posts/' . $ids[1] . '" >View Post</a>';
}
echo "</div>"; // close fb-update div
$i++; // add 1 to the counter if our condition for $post['type'] is met
}
// break out of the loop if counter has reached $numb
if ($i == $numb_of_posts) {
break;
}
} // end the foreach statement
}
echo "</div>";
?>
【问题讨论】:
标签: php facebook facebook-php-sdk