I'm working on a CMS that fetches a user's profile image from their facebook url (ie, 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?
Source: Tips4all
Simply fetch the data through this url:
ReplyDeletehttp://graph.facebook.com/sarfraz.anees/picture
Replace sarfraz.anees (my name) with name of the user you want to get the photo of.
You can use the PHP's file_get_contents function to read that url and process the retrieved data.
Resource:
http://developers.facebook.com/docs/api
Note: In php.ini, you need to make sure that openssl extension is enabled to use thefile_get_contents function of PHP to read that url.
To show:
ReplyDelete50x50 px:
<img src="https://graph.facebook.com/<?= $fid ?>/picture">
width: 200px
<img src="https://graph.facebook.com/<?= $fid ?>/picture?type=large">
To save:
$img = file_get_contents('https://graph.facebook.com/'.$fid.'/picture?type=large');
$file = dirname(__file__).'/avatar/'.$fid.'.jpg';
file_put_contents($file, $img);
Where $fid is your user id (or nickname) in facebook..
Is using
ReplyDeletehttps://graph.facebook.com/{user_id}/picture{?type=large}
instead of
https://graph.facebook.com/{user_username}/picture{?type=large}
is safer?
There are Facebook users which didn't set their username in Facebook.