Basics of Facebook API

I recently started developing a Facebook App, and i thought of sharing my experiences with all the people trying to get them started to build there own first app for facebook. By the way this is my first ever post in the world of blogging, so if i make any mistake or anything is not explained properly please lemme know and i will try to correct it. 🙂

Here is a link to get u started with Facebook apps. http://developers.facebook.com/docs/guides/canvas/

You can use these sdks: http://developers.facebook.com/docs/sdks/

You can download the sdks code from the link above, in this example iam using php-sdk.

The following code is a part of the example.php in the code provided in the php-sdk download. Create our Application instance (replace this with your appId and secret).

$facebook = new Facebook(array(
 'appId' => 'YOUR API ID',
 'secret' => 'YOUR API SECRET',
 'cookie' => true
));
$session = $facebook->getSession();
$me = null;

Session based API call.

if ($session) {
 try {
  $uid = $facebook->getUser(); // gets user id
  $me = $facebook->api('/me');
  $friends = $facebook->api('/me/friends'); // gets all the friends of the user
  $photos = $facebook->api('/me/photos'); // gets all user photos
  $albums = $facebook->api('/me/albums'); // gets all user albums
  $useralbums = $albums['data']; // store the album array
  foreach ($useralbums as $key => &$album) {
   $albumphotos = $facebook->api('/'.$album['id'].'/photos');
  }
 }
 catch (FacebookApiException $e) {
  error_log($e);
 }
}