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)
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
largewhen you get the photo (though you only get up to 200px):http://graph.facebook.com/UID/picture?type=large2.
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=TOKENWhich will return something along the lines of:
You can then access:
https://graph.facebook.com/12345678912345123?access_token=TOKENAnd choose an image size:
And choose your
PICTUREURLof 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.