Chr*_* W. 1 python facebook urlfetch facebook-graph-api
我正在使用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'])
Run Code Online (Sandbox Code Playgroud)
麻烦的是,这需要两个不同的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"
},
Run Code Online (Sandbox Code Playgroud)
然后,您可以访问:
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"
}
Run Code Online (Sandbox Code Playgroud)
并选择您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;
});
});
Run Code Online (Sandbox Code Playgroud)
我在引用中没有得到任何评价,但在使用测试样本时我确实提出了基本相同的FQL查询.当我用Google搜索时,这家伙只是打败了我FB.Data.query
.我想你必须编辑到python,如果你想在python中然后我可以挖掘.
归档时间: |
|
查看次数: |
10434 次 |
最近记录: |