How to write a Facebook App?

Writing a Facebook is as easy as signing up for Facebook account. There is just one prerequisite, you must have some sort of web hosting, steps given below use PHP so a web hosting with PHP support is required, and you must know how to upload files. Follow these steps

  1. Sign up for Facebook if you don’t have an account. If you can’t do this simple thing do not read further.
  2. Go to Account > Applications and add Facebook Developer application.
  3. Go to the app page, locate and click the “Set up new application” button.
  4. Follow the instructions which let you name your app and set other things.
  5. Dont bother if you dont understand anything in the forms. Fill what you understand and just pay attention to following fields:
    a) Under Canvas > Canvas Page URL, create a Canvas URL which will be your app’s URL on Facebook, for example “my-hello-world-app”
    b) Under Canvas > Canvas Callback URL, this will be URL where we will host our Facebook app, so if I host my app on kumarchetan.com, the URL will be http://www.kumarchetan.com/, easy
    c) Under Canvas > Canvas Settings > Render Method, choose FBML.
    Save changes.
  6. Download the client library from here: http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz
  7. Extract the library on your local machine and you will end with a folder with two sub folders. We will be using folder named “php”.
  8. Open “index.php” in your choice of editor and you will see following code
    <?php
    // Copyright 2007 Facebook Corp. All Rights Reserved.
    //
    // Application: Ye app puri philmy hai
    // File: 'index.php'
    // This is a sample skeleton for your application.
    //
    require_once 'facebook.php';
    $appapikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //Your API key
    $appsecret = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyy'; //and your secret ;-)
    $facebook = new Facebook($appapikey, $appsecret);
    $user_id = $facebook->require_login();// Login is required

    Delete everything after this code, we will simply say “Hello dear” with user name in our app.
  9. Add following
    echo 'Hello <fb:name uid="', $user_id, '" firstnameonly="true" />!';
  10. Upload all the files in php folder to the server which you provided in Canvas Callback URL.
  11. Go to URL http://app.facebook.com/my-hello-world-app, remember “my-hello-world-app” was Canvas URL for our app.
  12. Voila!!! Your app is ready!

This is a very very very basic app. You can add more interactivity to this app. You need to browse through http://developers.facebook.com/ and you can use my app here -> http://www.facebook.com/apps/application.php?id=111590402213823 which simply reads a flat file db of Bollywood dialogues and prints a random dialogue. It just goes a step further and asks for permission to publish the dialogue on profile wall. I have a test profile which is using this app and you can look at the wall: http://www.facebook.com/profile.php?id=100001044906526

Join the Conversation

2 Comments

  1. I wrote a simple movie review app on Facebook for my summer training project. No one except for a few of my friends understood the idea and it’s value. I felt I was delivering a presentation to zombies.

Leave a comment

Your email address will not be published. Required fields are marked *