2011-06-28 195 views
1

我正在使用Facebook Graph API。通過圖形API訪問Facebook個人資料照片

我想下載我所有的用戶的Facebook賬戶的圖片,以查看原始尺寸圖片。

https://graph.facebook.com/<user alias>/picture可讓您訪問用戶當前個人資料圖片的縮略圖。

如果我想下載用戶的全尺寸的個人資料照片,它看起來像我需要做這樣的事情在這個僞代碼...

# Get albums 
albums = fetch_json('https://graph.facebook.com/<user alias>/albums') 

# Get profile pictures album 
profile_picture_album = albums['data']['Profile Pictures'] # Get profile picture album 

# Get the pictures from that album 
profile_pictures = fetch_json('https://graph.facebook.com/<profile_picture_album_id>/photos') 

# Get the most recent (and therefore current) profile picture 
current_profile_picture = profile_pictures['data'][0] 
image = fetch_image_data(current_profile_picture['source']) 

麻煩的是,這需要兩個不同的API訪問和然後圖片下載。如果在相冊中有很多的專輯或圖片,那麼我需要處理分頁。

似乎應該有一個更快/更簡單的方式來訪問用戶的當前個人資料圖片。有人知道嗎?

(FYI:我碰巧使用Python這樣做,但我想答案應該是語言無關)

回答

7

我不認爲你可以在一個很好的一步做,但你有幾個選項:

,當你的照片(雖然你只能得到最多200像素),您可以指定large類型參數:

http://graph.facebook.com/UID/picture?type=large

2.

你可以只得到個人資料圖片專輯的封面照片 - 這始終是當前的個人資料圖片:

https://graph.facebook.com/UID/albums?access_token=TOKEN

這將沿着線返回的東西:

{ 
     "id": "123456781234", 
     "from": { 
      "name": "FirstName Surname", 
      "id": "123456789" 
     }, 
     "name": "Profile Pictures", 
     "link": "http://www.facebook.com/album.php?aid=123456&id=123456789", 
     "cover_photo": "12345678912345123", 
     "privacy": "friends", 
     "count": 12, 
     "type": "profile", 
     "created_time": "2000-01-23T23:38:14+0000", 
     "updated_time": "2011-06-15T21:45:14+0000" 
     }, 

然後您可以訪問:

https://graph.facebook.com/12345678912345123?access_token=TOKEN

,並選擇圖像尺寸:

{ 
    "id": "12345678912345123", 
    "from": { 
     "name": "FirstName Surname", 
     "id": "123456789" 
    }, 
    "name": "A Caption", 
    "picture": "PICTUREURL", 
    "source": "PICTURE_SRC_URL", 
    "height": 480, 
    "width": 720, 
    "images": [ 
     { 
     "height": 608, 
     "width": 912, 
     "source": "PICTUREURL" 
     }, 
     { 
     "height": 480, 
     "width": 720, 
     "source": "PICTUREURL" 
     }, 
     { 
     "height": 120, 
     "width": 180, 
     "source": "PICTUREURL" 
     }, 
     { 
     "height": 86, 
     "width": 130, 
     "source": "PICTUREURL" 
     }, 
     { 
     "height": 50, 
     "width": 75, 
     "source": "PICTUREURL" 
     } 
    ], 
    "link": "FACEBOOK_LINK_URL", 
    "icon": "FACEBOOK_ICON_URL", 
    "created_time": "2000-01-15T08:42:42+0000", 
    "position": 1, 
    "updated_time": "2011-06-15T21:44:47+0000" 
} 

,並選擇您所選擇的PICTUREURL

this blog禮貌:

//get the current user id 
FB.api('/me', function (response) { 

    // the FQL query: Get the link of the image, that is the first in the album "Profile pictures" of this user. 
    var query = FB.Data.query('select src_big from photo where pid in (select cover_pid from album where owner={0} and name="Profile Pictures")', response.id); 
    query.wait(function (rows) { 

    //the image link 
    image = rows[0].src_big; 
    }); 
}); 

這一點我不採取任何信貸報價,但與測試樣品玩耍時,我沒有拿出基本相同FQL查詢。當我搜索FB.Data.query時,這傢伙只是打了我一拳。我想你將不得不將它編輯成python,如果你想用python,那麼我可以挖掘它。

+0

不錯! 200px one *可能足以滿足我的目的,但除此之外,我會嘗試FQL查詢(我將弄清python,不用擔心。)謝謝! –

+0

好吧,問問你是否需要澄清! – BeRecursive

+0

僅供參考,我最終使用了200px'type = large'解決方案,但是非常感謝您的回答! –

3

這說明原來的全尺寸版個人資料圖片:

https://graph.facebook.com/someuser/picture?width=9999&height=9999

相關問題