Facebook API - How do I get a Facebook user's profile image through the Facebook API [without requiring the user to "Allow" the application]
Simply fetch the data through this URL:
//graph.facebook.com/userid_here/picture
Replace userid_here with id of the user you want to get the photo of. You can also use HTTPS as well.
You can use the PHP's file_get_contents function to read that URL and process the retrieved data.
Resource:
//developers.facebook.com/docs/api
Note: In php.ini, you need to make sure that the OpenSSL extension is enabled to use thefile_get_contents function of PHP to read that URL.
To show:
50x50 pixels
200 pixels width
To save [using PHP]
NOTE: Don't use this. See @Foreever's comment below.
$img = file_get_contents['//graph.facebook.com/'.$fid.'/picture?type=large']; $file = dirname[__file__].'/avatar/'.$fid.'.jpg'; file_put_contents[$file, $img];Where $fid is your user id on Facebook.
NOTE: In case of images marked as "18+" you will need a valid access_token from a 18+ user:
UPDATE 2015:
Graph API v2.0 can't be queried using usernames, you should use userId always.
UPDATE:
Starting end August 2012, the API has been updated to allow you to retrieve user's profile pictures in varying sizes. Add the optional width and height fields as URL parameters:
//graph.facebook.com/USER_ID/picture?width=WIDTH&height=HEIGHTwhere WIDTH and HEIGHT are your requested dimension values.
This will return a profile picture with a minimum size of WIDTH x HEIGHT while trying to preserve the aspect ratio. For example,
//graph.facebook.com/redbull/picture?width=140&height=110returns
{ "data": { "url": "//fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/c0.19.180.142/s148x148/2624_134501175351_4831452_a.jpg", "width": 148, "height": 117, "is_silhouette": false } }END UPDATE
To get a user's profile picture, call
//graph.facebook.com/USER_ID/picturewhere USER_ID can be the user id number or the user name.
To get a user profile picture of a specific size, call
//graph.facebook.com/USER_ID/picture?type=SIZEwhere SIZE should be replaced with one of the words
square small normal largedepending on the size you want.
This call will return a URL to a single image with its size based on your chosen type parameter.
For example:
//graph.facebook.com/USER_ID/picture?type=smallreturns a URL to a small version of the image.
The API only specifies the maximum size for profile images, not the actual size.
Square:
maximum width and height of 50pixels.
Small
maximum width of 50pixels and a maximum height of 150pixels.
Normal
maximum width of 100pixels and a maximum height of 300pixels.
Large
maximum width of 200pixels and a maximum height of 600pixels.
If you call the default USER_ID/picture you get the square type.
CLARIFICATION
If you call [as per above example]
//graph.facebook.com/redbull/picture?width=140&height=110it will return a JSON response if you're using one of the Facebook SDKs request methods. Otherwise it will return the image itself. To always retrieve the JSON, add:
&redirect=falselike so:
//graph.facebook.com/redbull/picture?width=140&height=110&redirect=false