Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 513
Odyss3us Avatar asked Jun 10 '10 08:06

Odyss3us


People also ask

How do I post a photo from Facebook graph API?

Publishing an Photo With that granted, you can upload a photo by issuing an HTTP POST request with the photo content and an optional description to one these to Graph API connections: https://graph.facebook.com/USER_ID/photos - The photo will be published to an album created for your app.

What data can I get from Facebook graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.


2 Answers

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

like image 163
hndcrftd Avatar answered Sep 28 '22 12:09

hndcrftd


to get different sizes, you can use the type parameter:

You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), and large (about 200 pixels wide, variable height): http://graph.facebook.com/squall3d/picture?type=large.

like image 28
squall3d Avatar answered Sep 28 '22 13:09

squall3d