How can I display the users profile pic using the facebook graph api?

Odyss3us picture Odyss3us · Jun 10, 2010 · Viewed 115.1k times · Source

I would like to display the users profile picture inside of my applications canvas page, is there a way to do that using the graph api?

I know I can do it using FBML but I would also like to pass the profile pic to a flash game I am making, so I would have to get the profile pic from the api and send it as a variable, here is the code I have thus far,

$facebook = new Facebook(array(
    'appId'  => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_SECRET_KEY,
    'cookie' => true,
    'domain' => 'myurl/facebook-test'
));

$session = $facebook->getSession();

        $uid = $facebook->getUser();
        $me = $facebook->api('/me');

        $updated = date("l, F j, Y", strtotime($me['updated_time']));

        echo "Hello " . $me['name'] . $me['picture'] . "<br />";
  echo "<div style=\"background:url(images/bg.jpg); width:760px; height:630px;\">" . "You last updated your profile on " . $updated . "</div>" . "<br /> your uid is" . $uid;

$me['picture'] does not seem to be working, but I am still very new to the graph api, and I am probably making a few very amateur mistakes!

Answer

hndcrftd picture hndcrftd · Jun 10, 2010

Knowing the user id the URL for their profile picture is:-

http://graph.facebook.com/[UID]/picture

where in place of [UID] you place your $uid variable, and that URL can be passed to flash