This is a guest article written by freelance programmer Ville-Matti Hakanpää
In this brief introductory tutorial I will go through some basic aspects of Facebook application development. The work itself is basic app programming, but it’s a whole new world and environment. If you have a wonderful idea, Facebook can work as a great distribution channel for you. Heck, even a bad idea can get some attention fast!
Start out with the most basic of questions, though: what makes a good app?
That’s the first and most common question people are asking or they should be asking. The best way to start when you’re trying to decide what to develop is to look through all the other applications what are inside Facebook already. Facebook applications are listed and rated by users, so there’s a feedback loop there too that tells you the kind of things people find useful and engaging.
The most popular one for now is a game called Farmville, with 73 million active users per month, which is over double the next two combined. In general, games are very popular inside Facebook. For me that reveals few things. First of all people like to play games. Entertainment is a hot topic. Second of all, Facebook doesn’t have any fun games to offer for own users, hence the popularity of third party apps.
The most popular “ordinary” application is Causes, which provides an opportunity to donate money to different non-profit projects. While charity is important, it doesn’t comply with useful, “needed-daily” idea. Think about non-Facebook programs like Google. Would you survive without it? You might, but it makes your life so much easier that you probably choose to use it anyway, many times during the day. If you can create something like that for Facebook, well, you’ll have gold in your hands.
Technically you have two different possible approaches you can choose from. You can use Facebook’s own technology (FBML, FBJS and FQL) or you can use an API client. Difference is that when you are using FBML (Facebook Markup Language) for example, you are mainly using Facebook’s server and its resources. This way you can save you own server. Using API is the complete opposite.
Let’s compare these. First let’s create a “Hello World” application with PHP5 API client:
// include the Facebook client library
// define your API Key and secret
$facebook_config['api_key'] = ‘<YOUR_APPLICATIONS_API_KEY>';
$facebook_config['secret'] = ‘<YOUR_APPLICATIONS_SECRET_KEY>';
// create the Facebook object
$facebook = new Facebook($facebook_config['api_key'], $facebook_config['secret']);
// require user to be logged in’
$user = $facebook->require_login();
// define your callback URL
$callback_url = ‘http://<URL_TO_THE_APPLICATION_AT_YOUR_END>/';
And same thing with FBM:
<fb:redirect url=”http://www.facebook.com/login.php?v=1.0&api_key=<YOUR_API_KEY>&canvas=http://< URL_TO_THE_APPLICATION_AT_YOUR_END >” />
Both examples will check if the user has approved the application and then prints out words “Hello World”. While FBML looks and is much more simple way to do things, it has huge limitations when you compare it to PHP for example. FBML is wary easy to compare with HTML which was the starting point when FBML was developed. Can you build rich web applications using HTML only? Hardly…
The question what should be asked is not which one I should be using, but how to use them both. Let’s create a invitation form to show my point:
<USE THE SAME PHP CODE AS IN FIRST EXAMPLE>
content=”I say this is a one cool app!<fb:req-choice
url=’http://apps.facebook.com/greattestapp/’ label=’Confirm’ />”>
<fb:multi-friend-selector actiontext=”Tell all your friends! Tell the whole bunch!” />
This looks rather simple, but the mechanism behind it is really helpful and sophisticated. You are gathering all your friends and bringing them into a clickable list. From this point you can grow it to whatever you like with smaller resources required than a normal web application.
Now your program could invite more people and it has requested the basic privileges. That’s hardly enough but it’s a good start. Now the real developing begins. Use your knowledge of PHP and start learning those Facebook Technologies what I mentioned. Anytime you get stuck, there is a place to go. For like minded people The Facebook Developers Forum provides the support you need. While Facebook development is rather new and is partly in beta state, you will need help and extra revealing information. Go to the forums now and start digging.
Author ille-Matti Hakanpää is a freelance PHP programmer. His personal website concentrates on PHP training with Facebook in mind.