1

我正在使用 Facebook 图形 API。

我想下载我所有用户的 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 访问,然后是图像下载。如果相册中有很多相册或图片,那么我需要处理分页。

似乎应该有一种更快/更简单的方式来访问用户当前的个人资料图片。有人知道吗?

(仅供参考:我碰巧正在使用 Python 来执行此操作,但我想答案将与语言无关)

4

2 回答 2

7

我不认为你可以一步到位,但你确实有几个选择:

1.

您可以指定large获取照片时的类型参数(尽管您最多只能获取 200 像素):

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的选择。

3.

本博客提供:

//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 中,那么我可以挖掘。

于 2011-06-28T21:12:43.720 回答
4

这显示了个人资料图像的原始全尺寸版本:

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

于 2013-02-25T14:42:30.620 回答