我正在使用Facebook Graph 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来执行此操作,但我认为答案与语言无关)
最佳答案
我认为您不能一步一步完成,但是您有几种选择:
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。
由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中进行编辑,那么我可以进行深入研究。关于python - 通过Graph API“轻松”访问Facebook个人资料照片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6512938/