“简单”通过 Graph API 访问 Facebook 个人资料照片
我正在使用 Facebook Graph API。
我想下载所有用户的 Facebook 个人资料图片的完整尺寸图像。
https://graph.facebook.com/
使您可以访问用户当前个人资料图片的小缩略图。
如果我想下载用户的全尺寸个人资料照片,看起来我需要执行类似于此伪代码的操作...
# 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您无法一步到位地完成此任务,但您确实有几个选择:
1.
当您获得照片(尽管您最多只能获得 200 像素):
http://graph.facebook.com/UID/picture?type=large
2.
您可以直接获取封面个人资料图片相册的照片 - 始终是当前个人资料图片:
https://graph.facebook.com/UID/albums?access_token=TOKEN
这将返回以下内容:
然后您可以访问:
https://graph.facebook.com /12345678912345123?access_token=TOKEN
并选择图像大小:
然后选择您选择的
PICTUREURL
。3.
由此博客:
我没有引用该博客,但我在使用测试示例时确实想出了基本相同的 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:
You can then access:
https://graph.facebook.com/12345678912345123?access_token=TOKEN
And choose an image size:
And choose your
PICTUREURL
of choice.3.
Courtesy of this blog:
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.这显示了个人资料图片的原始全尺寸版本:
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