Python &引用;“容易”;通过Graph API访问Facebook个人资料照片

Python &引用;“容易”;通过Graph API访问Facebook个人资料照片,python,facebook,facebook-graph-api,urlfetch,Python,Facebook,Facebook Graph Api,Urlfetch,我正在使用Facebook图形API 我想下载所有用户Facebook个人资料图片的全尺寸图片 https://graph.facebook.com//picture允许您访问用户当前个人资料图片的缩略图 如果我想下载用户的全尺寸个人资料照片,看起来我需要在这个伪代码中执行类似的操作 # Get albums albums = fetch_json('https://graph.facebook.com/<user alias>/albums') # Get profile pic

我正在使用Facebook图形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'])
#获取相册
albums=fetch_json('https://graph.facebook.com//albums')
#获取个人资料图片相册
profile_picture_album=相册['data']['profile Pictures']#获取个人资料相册
#从那本相册中获取图片
profile\u pictures=fetch\u json('https://graph.facebook.com//photos')
#获取最新(因此也是最新)的个人资料图片
当前配置文件图片=配置文件图片['data'][0]
image=fetch\u image\u数据(当前配置文件\u图片['source'])
问题是,这需要两个不同的API访问,然后下载图像。如果相册中有很多相册或图片,那么我需要处理分页

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


(仅供参考:我碰巧使用Python来实现这一点,但我认为答案是语言不可知的)

我认为您不可能一步到位,但您确实有一些选择:

1.

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

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.

承蒙:


我在引用时没有考虑到这一点,但在处理测试样本时,我确实提出了基本相同的FQL查询。当我在谷歌上搜索FB.Data.query时,这家伙狠狠地揍了我一顿。我想你必须在python中编辑它,如果你想在python中编辑它,那么我可以仔细研究。

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

1.

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

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.

承蒙:


我在引用时没有考虑到这一点,但在处理测试样本时,我确实提出了基本相同的FQL查询。当我在谷歌上搜索FB.Data.query时,这家伙狠狠地揍了我一顿。我想你必须在python中编辑它,如果你想在python中编辑它,那么我可以到处看看。

这显示了配置文件图像的原始全尺寸版本:


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

这显示了配置文件图像的原始全尺寸版本:


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

不错!对于我来说,200px一个就足够了,否则我将尝试FQL查询(我会找出python,不用担心。)谢谢!仅供参考,我最终使用了200px
type=large
解决方案,但感谢您提供了非常全面的答案!美好的对于我来说,200px一个就足够了,否则我将尝试FQL查询(我会找出python,不用担心。)谢谢!仅供参考,我最终使用了200px
type=large
解决方案,但感谢您提供了非常全面的答案!