Reputation: 39219
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)
Upvotes: 1
Views: 11846
Reputation: 27613
This shows the original full size version of the profile image:
https://graph.facebook.com/someuser/picture?width=9999&height=9999
Upvotes: 4
Reputation: 6376
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.
Upvotes: 7