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
- Sign up for Facebook if you don’t have an account. If you can’t do this simple thing do not read further.
- Go to Account > Applications and add Facebook Developer application.
- Go to the app page, locate and click the “Set up new application” button.
- Follow the instructions which let you name your app and set other things.
- 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.
- Download the client library from here: http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz
- 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”.
- Open “index.php” in your choice of editor and you will see following code
// Copyright 2007 Facebook Corp. All Rights Reserved.
// Application: Ye app puri philmy hai
// File: 'index.php'
// This is a sample skeleton for your application.
$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.
- Add following
echo 'Hello <fb:name uid="', $user_id, '" firstnameonly="true" />!';
- Upload all the files in php folder to the server which you provided in Canvas Callback URL.
- Go to URL http://app.facebook.com/my-hello-world-app, remember “my-hello-world-app” was Canvas URL for our app.
- 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