We are working on a CMS that fetches a user’s profile image from their Facebook URL (that is, http://facebook.com/users_unique_url).
How can we accomplish this? Is there a Faceboook API call that fetches a user’s profile image URL without the user needing to Allow the application?
- Simply fetch the data through this URL:
- Replace user id_ 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.
Note: In php.ini, you need to make sure that the OpenSSL extension is enabled to use the file_get_contents function of PHP to read that URL.
- 50×50 pixels
- 200 pixels width
To save (using PHP)
NOTE: Don’t use this. See @Forever’s comment below.
Where $fid is your user id (or nickname) on Facebook..
NOTE: In case of images marked as “18+” you will need a valid access_token from a 18+ user:
- 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:
- where 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,
- To get a user’s profile picture, call
- where USER_ID can be the user id number or the user name.
- To get a user profile picture of a specific size, call
- where SIZE should be replaced with one of the words
- depending 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:
returns a URL to a small version of the image.
- The API only specifies the maximum size for profile images, not the actual size.
- maximum width and height of 50 pixels.
- maximum width of 50 pixels and a maximum height of 150 pixels.
- maximum width of 100 pixels and a maximum height of 300 pixels.
- maximum width of 200 pixels and a maximum height of 600 pixels
If you call the default USER_ID/picture you get the square type.
- If you call (as per above example)
- It 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:
- Maybe ID will be a useful tool. Every time a user creates a new account it should get a higher ID.
Read this article:
- Here is a clean-cut code function for such process!
- This will return the raw Facebook avatar image URL.
- To get the image URL, NOT binary content:
- You must use your FACEBOOK ID, NOT USERNAME. You can get your facebook id there: