2012-03-22 63 views
11

我正在打開我的頁面牆。 當有人發佈了一張照片,我得到它的JSON獲取張貼在頁面牆上的高分辨率照片/供稿

{ 
    "id": "27888702146_10150369820322147", 
    "from": { 
     "name": "brocoli", 
     "category": "Record label", 
     "id": "27888702146" 
    }, 
    "message": "Vincent Epplay/David Fenech/Jac Berrocal \u00e0 Beaubourg ce soir, 19h, gratos.", 
    "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc7/305819_10150369820292147_27888702146_8255527_583491475_s.jpg", 
    "link": "https://www.facebook.com/photo.php?fbid=10150369820292147&set=a.386279807146.165840.27888702146&type=1", 
    "icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif", 
    "type": "photo", 
    "object_id": "10150369820292147", 
    "created_time": "2011-10-16T08:22:21+0000", 
    "updated_time": "2011-10-16T08:22:21+0000", 
    "likes": { 
     "data": [ 
      { 
       "name": "brocoli", 
       "category": "Record label", 
       "id": "27888702146" 
      }, 
      { 
       "name": "Agathe Morier", 
       "id": "601668526" 
      } 
     ], 
     "count": 2 
    }, 
    "comments": { 
     "count": 0 
    }, 
    "is_published": true 
    } 

的問題是,圖片鏈接是圖片的低分辨率副本。

如何獲取完整圖片的網址?

謝謝!

最佳

弗魯瓦

+0

你有解決方案,下面的答案不起作用。 – 2014-10-20 08:28:04

回答

17

您可以通過查詢圖形API得到不同版本的photo與它object_id(不是照片post_id這是你所提供的結果id)。

一旦你將請求與URL和尺寸的imagesphoto的對象id你會得到數組:

http://graph.facebook.com/10150369820292147?fields=images 
+0

太棒了!它像一個魅力!非常感謝! – geoffroy 2012-03-22 21:14:43

+0

非常感謝...完美 – Superdev 2013-08-09 07:57:27

+0

非常感謝。很好的回答:) – Supertecnoboff 2014-03-23 10:09:59

2

使用此代碼。它的工作對我來說並獲得清晰影像

String PICTURE_URL; 

String getPicture = hashMap.get("picture"); 
     if (getPicture.contains("_t.")) { 
      PICTURE_URL = getPicture.replaceAll("_t.", "_n."); 
     } else if (getPicture.contains("_a.")) { 
      PICTURE_URL = getPicture.replaceAll("_a.", "_n."); 
     } else if (getPicture.contains("_s.")) { 
      PICTURE_URL = getPicture.replaceAll("_s.", "_n."); 
     } else if (getPicture.contains("_q.")) {    
      PICTURE_URL = getPicture.replaceAll("_q.", "_n."); 
     } 
     url=new URL(PICTURE_URL); 
     Bitmap bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
     ((ImageView)view.findViewById(R.id.imageView_FullImage)).setImageBitmap(bitmap); 
+0

可能有點哈克,但它的作品;) – stealthcopter 2013-07-30 11:41:57

+1

由我有時有時,有時不工作....爲什麼Facebook讓圖像這麼愚蠢 – 2014-01-03 13:17:57

+3

它似乎沒有工作 – 2014-09-16 01:28:10

4

您可以從主帖列表做到這一點現在用

/v2.3/105753476132681/posts?limit=5&fields=likes.summary(true),comments.summary(true), attachments 

如果附件不能正常工作,嘗試full_picture - 但這只是給了100x100的圖像對我來說也是如此。

附件返回一個數據散列至少640x480的版本的圖像。(不知道我的原稿照片尺寸了。)

5

所有你需要做的是:

http://graph.facebook.com/me?fields=picture.height(961) 
// replace 961 with your required height which u want 
+1

這應該是接受的答案。只有一件事現在正在工作。 – 2016-02-13 14:38:06

3

雖然請求通過其object_id的照片將返回具有不同尺寸的圖像數組,在某些情況下,這種方法需要額外的Facebook API調用。

一個更簡單的方法是將full_picture添加到參數列表中,該列表將提取與該帖子關聯的最高分辨率圖像。

/v2.2/6275848869/posts?fields=full_picture 

例如,如果你想提取從過去X天一個Facebook頁面的所有帖子,與object_id方法,你就需要調用API 3次:

  1. 要獲取頁面信息。
  2. 提取帖子列表並獲取每個帖子的object_id
  3. 對於每個object_id,檢索更高分辨率圖像的列表。
相關問題