2

I am using the Facebook Graph API to get the news feed of a user.

My request URL is: xxxxxxxxxxxxxx/feed?fields=from,id,created_time,picture,link,object_id,message, likes.fields(id)

With the object_id, I want to get the big picture of the post, using the following url: http://graph.facebook.com/OBJECT_ID/picture?type=normal

The picture return field is always filled, but the object_id is not being returned at some posts. Why is this? I really need the high res picture, and didn't find another way to acquire this..

4

3 回答 3

1

仅当附件是 facebook 对象(例如用户上传的图像)时才返回 object_id。提要中的一些故事根本没有图片,有些图片不是 facebook 对象(例如共享链接的缩略图)。

于 2013-10-10T17:33:07.637 回答
0

有时,Facebook 会保留图像的缩略图,并在图形请求返回的 URL 中存储指向更大版本图像的外部链接。为了在任何一种情况下访问图像,我都使用了下面的代码,其中 smallURL 是图形请求返回的 URL:

private String getRealURL(String smallURL){
   if (smallURL.contains("url=http")){
       String[] pieces = smallURL.split("url=");
       pieces[1].replace("%2F", "//");
       pieces[1].replace("%3A", ":");
       return pieces[1];           
   }
   else{
       StringBuilder stringBuilder = new StringBuilder();
       stringBuilder.setLength(0);
       stringBuilder.append("http://graph.facebook.com/");
       stringBuilder.append(item.getObjectID());
       stringBuilder.append("/picture?type=large");
       return stringBuilder.toString();
   }
}
于 2014-06-20T07:08:39.897 回答
0

我还注意到一些 FB 帖子没有{object_id}大照片,但意识到{picture}缩略图 URL 包含原始大图像的编码 URL:

https://external.xx.fbcdn.net/safe_image.php?d=AQBe9UvGd0vPbAHP&w=130&h=130&url=http%3A%2F%2Fskift.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fpollution.jpg&cfs=1

--> 包含 -->

http://skift.com/wp-content/uploads/2015/12/pollution.jpg

所以我检查{object_id},如果没有,然后尝试从以下位置提取原始 URL {picture}

if(isset($post['object_id'])) {
    echo "http://graph.facebook.com/".$post['object_id']."/picture";
    }
    elseif(isset($post['picture'])) {
        echo urldecode(preg_replace('/&cfs.*/', '', preg_replace('/.*url=/', '', $post['picture'])));
    } 
    else {
        echo "no_large_image";
}
于 2016-01-12T10:48:25.467 回答