Joyent (http://www.joyent.com) recently partnered with Facebook to provide a free year of hosting for Facebook applications (http://joyent.com/developers/facebook). There is a waiting list, but it is a pretty good deal for a really good host. Other hosts that have a proven track record with Facebook apps include MediaTemple (http://www.mediatemple.net) and Dreamhost (http://www.dreamhost.com/). If you’re thinking smaller, you might want to try RunHosting (http://facebook.runhosting.com) or 110MB (http://www.110mb.com). It’s good to look at a few and see which one offers the best fit for what you want to do. Many of these web sites also have free database hosting (usually MySQL), which is a great way to get up and running with Facebook application development.

To get up and running with developing an online Facebook application, you need to have three things in place:

  1. A valid Facebook account
  2. Access to a web server running a supported middleware language
  3. The client library for your particular middleware language.
If you’re working on a desktop application, you still need a Facebook account (for authentication), but you will need only the client library for your language because your interactions with the Facebook servers will be handled by your program and not a web server.

To minimize the threat of cross-site scripting (XSS) attacks, Facebook implemented its own JavaScript for developers who really want, or need, to use JavaScript in their applications. Facebook removes much of the JavaScript you can add to your application, but by using Facebook JavaScript (FBJS) you can still enrich the user’s experience. Facebook formally released FBJS 1.0 in September 2007. The following is a quick example of how you can provide a modal dialog box to your users:

<a href="#" onclick="new Dialog().showMessage('Dialog', 'This is the help message for this link');return false">Show Dialog Box</a>

When processed through the Facebook platform, a user will be shown the model dialog box as shown in the figure after clicking the Show Dialog Box hyperlink. Not bad for a single line of code!


The Facebook Query Language (FQL) is a SQL-style language specifically designed to allow developers to interact with Facebook information. Facebook allows you to interact with nine separate “tables” to query information directly. You have access to the following:

  • user
  • friend
  • group
  • group_member
  • event
  • event_member
  • photo
  • album
  • phototag

Facebook exposes a lot of information to you for your application. And, like most SQL implementations, some additional functions allow you to take a few shortcuts when you request user information:

  • now() returns the current time.
  • strlen(string) returns the length of the string passed to the function.
  • concat(string1, string2,, stringN) concatenates N strings together.
  • substr(string, start, length) returns a substring from a given string.
  • strpos(haystack, needle) returns the position of the character needle in the string haystack.
  • lower(string) casts the given string to lowercase.
  • upper(string) casts the given string to uppercase.

To write FQL, you follow basic SQL syntax. For example, to extract my name and picture from Facebook, you would write a simple query like so:

SELECT name, pic
FROM user
WHERE uid = 7867867

When executed by the Facebook platform, it will return a structure (in a format that you define in your call) with a URL to the image of the profile image for user 7867867. Calls like these are useful in giving you control of the information you get back from the API.

Facebook API calls are grouped into eight action categories. These calls are really wrappers for more sophisticated FQL interactions with the Facebook back end but are useful bits of code that speed up the development of your application. These calls include the following:

  • facebook.auth provides basic authentication checks for Facebook users.
  • facebook.feed provides methods to post to Facebook news feeds.
  • facebook.friends provides methods to query Facebook for various checks on a user’s friends.
  • facebook.notifications provides methods to send messages to users.
  • facebook.profile allows you to set FBML in a user’s profile.
  • facebook.users provides information about your users (such as content from the user’s profile and whether they are logged in).
  • facebook.events provides ways to access Facebook events.
  • facebook.groups provides methods to access information for Facebook groups.
  • facebook.photos provides methods to interact with Facebook photos.