tags:

views:

2143

answers:

4

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?

+4  A: 

Simply 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.

Sarfraz
Thanks! That is exactly what I was looking for!
John Himmelman
Looking through that page further, another useful thing might be the `?type=large` querystring you can add on. Props for coming up with a totally much better answer than the screen-scraping I was typing up, BTW :).
Domenic
@John Himmelman: You are welcome :)
Sarfraz
@Domenic: Yup, the new graph API looks to be cool and promising :)
Sarfraz
+1  A: 
Gamlet
+1  A: 

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.

benjaminlotan
A: 

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).

moostring