“简单”通过 Graph API 访问 Facebook 个人资料照片

发布于 2024-11-17 23:32:58 字数 951 浏览 5 评论 0原文

我正在使用 Facebook Graph API。

我想下载所有用户的 Facebook 个人资料图片的完整尺寸图像。

https://graph.facebook.com//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 来执行此操作,但我想答案与语言无关)

I'm using the Facebook Graph API.

I would like to download the full size image of all my users' Facebook profile pictures.

https://graph.facebook.com/<user alias>/picture gives you access to a tiny thumbnail of the user's current profile picture.

If I want to download the user's full size profile photo it looks like I need to do something like in this pseudo-code...

# 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'])

The trouble is that this requires two different API accesses and then the image download. And if there are a lot of albums or pictures in an album then I'll need to deal with paging.

It seems like there should be a faster/easier way to access the user's current profile picture. Anybody know of one?

(FYI: I happen to be using Python to do this but I imagine the answer would be language agnostic)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倚栏听风 2024-11-24 23:32:58

我认为您无法一步到位地完成此任务,但您确实有几个选择:

1.

当您获得照片(尽管您最多只能获得 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 查询。当我在 google 上搜索 FB.Data.query 时,这个家伙就先发制人了。我想你必须将其编辑到Python中,如果你想在Python中使用它,那么我可以四处挖掘。

I don't think you can do it in one nice step, but you do have a few options:

1.

You can specify a type argument of large when you get the photo (though you only get up to 200px):

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

2.

You could just get the cover photo of the profile pictures album - which is always the current profile picture:

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

Which will return something along the lines of:

{
         "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"
      },

You can then access:

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

And choose an image size:

{
   "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"
}

And choose your PICTUREURL of choice.

3.

Courtesy of 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;
  });
});

Which I take no credit in quoting, but I did come up with basically the same FQL query when playing around with a test sample. This guy just beat me to the punch when I googled FB.Data.query. I imagine you will have to edit that in to python, if you want it in python then I could dig around.

喜你已久 2024-11-24 23:32:58

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

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

This shows the original full size version of the profile image:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文