I'm 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 I accomplish this? Is there a Faceboook API call that fetches a user's profile image URL without the user needing to Allow the application?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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:
where
WIDTH
andHEIGHT
are your requested dimension values.This will return a profile picture with a minimum size of
WIDTH
xHEIGHT
while trying to preserve the aspect ratio. For example,returns
END UPDATE
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 wordsdepending 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.
Square:
Small
Normal
Large
If you call the default USER_ID/picture you get the square type.
CLARIFICATION
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:
like so:
Are you concerned about the profile picture size? at the time of implementing login with Facebook using PHP. We’ll show you the simple way to get large size profile picture in Facebook PHP SDK. Also, you can get the custom size image of Facebook profile.
Set the profile picture dimension by using the following line of code.
$userProfile = $facebook->api('/me?fields=picture.width(400).height(400)');
check this post:http://www.codexworld.com/how-to-guides/get-large-size-profile-picture-in-facebook-php-sdk/
You can get the profile URI via online facebook id finder tool
You can also pass type param with possible values small, normal, large, square.
Refer the official documentation
To show:
50x50 pixels
200 pixels width
To save (using PHP)
NOTE: Don't use this. See @Foreever's comment below.
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.Simple one-line code to save FULL size profile image on your server.
This will only work if openssl will be enabled in php.ini.
Added this as a comment to accepted answer, but felt it deserved a longer explanation. Starting around April 2015 this will probably be raised a few times.
As of V2 of the graph api the accepted answer no longer works using a username. So now you need the userid first, and you can no longer use a username to get this. To further complicate matters, for privacy reasons, Facebook is now changing userid's per app (see https://developers.facebook.com/docs/graph-api/reference/v2.2/user/ and https://developers.facebook.com/docs/apps/upgrading/#upgrading_v2_0_user_ids ), so you will have to have some kind of proper authentication to retrieve a userid you can use. Technically the profile pic is still public and available at /userid/picture (see docs at https://developers.facebook.com/docs/graph-api/reference/v2.0/user/picture and this example user: http://graph.facebook.com/v2.2/4/picture?redirect=0) however figuring out a user's standard userid seems impossible based just on their profile - your app would need to get them to approve interaction with the app which for my use case (just showing a profile pic next to their FB profile link) is overkill.
If someone has figured out a way to get the profile pic based on username, or alternatively, how to get a userid (even an alternating one) to use to retrieve a profile pic, please share! In the meantime, the old graph url still works until April 2015.