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?
views:
2143answers:
4Simply fetch the data through this url:
http://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.
ONE WAY TO USE THE CODE GAMLET POSTED IN HIS ANSWER:
save it as curl.php
then in your file
require 'curl.php';
$photo="https://graph.facebook.com/me/picture?access_token=".$session['access_token'];
$sample = new sfFacebookPhoto;
$thephotoURL=$sample->getRealUrl($photo);
echo $thephotoURL;
i thought i would post this, because it took me a bit of time to figure out the particulars... even though profile pictures are public, you still need to have an access token in there to get it when you curl it.
This might offer another form of solution.
http://markuzweb.blogspot.com/2010/09/grab-picture-of-facebook-graph-object.html
Use the code in the tutorial along with the Facebook's Graph API and its PHP SDK library.
...and try not to use file_get_contents (unless you're ready to face the consequences).