Writing Facebook Applications Using Java EE
Facebook is a popular social networking platform where people connect with family, friends, and like-minded individuals and engage in a variety of possible online activities. A large variety of these activities are made possible through so-called Facebook applications. These applications make use of the Facebook web services and APIs to integrate with the Facebook site, access the Facebook user's social information, and extend Facebook's social platform.
The Facebook Application Model
Facebook uses a proxy server model to allow web developers to integrate to its platform. With the proxy server model, Facebook can open its platform to developers through REST web services, and can provide APIs with high integrability to the Facebook look and feel, without needing to provide hosting services for each and every third-party application. Developers are also free to engineer their applications as they wish, choosing almost any technology they desire to write their app. This creates an even playing field for all developers, at least when it comes to development costs: Developers still need to deploy their apps in a way that can handle potentially millions of users per day. It is not uncommon for a popular Facebook app to grow to a million users within a single week.
The proxy model works like this:
- Your Facebook application lives on your server; you register the base URL of your Facebook app with Facebook
- When a user visits your application on Facebook, Facebook calls the corresponding URL on your server
- Your app calls the Facebook API to get information about the user and their friends and to update the user's profile page
- Your app uses information from its own database and session, and from the Facebook user data, and renders a page with the output from its action
- In the case of an iframe canvas page, Facebook wraps the output of your application in an HTML iframe
- Facebook then returns your app's output to the user, wrapped in the Facebook navigation headers, footers and sidebars
Writing Facebook applications using Java has proven difficult for many developers. The official Facebook Java libraries were often buggy and not updated as often as the official PHP libraries. To add insult to injury, nearly all official Facebook documentation and sample code (and a good deal of examples out on the blogosphere) are for PHP development. Luckily, a group of independent developers proceeded to implement their own improved and maintained clone of the Facebook API libraries for Java, removing one major obstacle for Java development. This article hopes to provide concise information about how to use these unofficial libraries to create a Facebook web application, and hopefully eliminate the last hurdle for Java developers.
Before beginning to write code, you must first sign up and log in to Facebook. Then, add the Facebook Developer Application to your user profile by visiting the following URL: http://www.facebook.com/developers/. The Facebook Developer Application is where developers request the API keys and the Facebook web address from which their application will be accessed. The Facebook Developer Application is also a public group where Facebook developers can help each other with the API and with proper use of the Facebook Developer App itself.
Figure 1: Facebook sign-up page
Figure 2: Facebok Developer Application at http://www.facebook.com/developers/
Once you have added the Facebook Developer Application, you can register your intended web application with Facebook. Don't worry that you don't have an application deployed yet; the information you will fill in is quite basic and will help organize how the app is developed. To begin, click the "Setup New Application" button on the Facebook Developer App page. This will open the "New Application" page on Facebook.
Figure 3: Facebok's "New Application" page