Getting to Grips with the Facebook Platform

5 min read

The Purpose of the Facebook Platform

As you develop your Facebook applications, you’ll find that the Facebook Platform is essential—in fact you won’t really be able to do anything without it. So what does it do? Well, before answering that, let’s look at a typical web-based application.

The Standard Web Application Model

If you’ve ever designed and built a web application before, then you’d have done it in a fairly standard way. Your application and any associated data would have been placed on a web server, and then your application users will access it from their web browsers via the Internet:

Getting to Grips with the Facebook Platform

The Facebook model is slightly different.

The Facebook Web Application Model

As far as your application users are concerned, they will just access and your application, by using a web browser and the Internet. But, that’s not where the application lives—it’s actually on your own server:

Getting to Grips with the Facebook Platform

Once you’ve looked at the Facebook web application model and realized that your application actually resides on your own server, it becomes obvious what the purpose of the Facebook Platform is—to provide an interface between your application and itself.

There is an important matter to be considered here. If the application actually resides on your server, and your application becomes very successful (according to Facebook there are currently 25 million active users), then will your server be able to able to cope with that number of hits?

Don’t be too alarmed. This doesn’t mean that your server will be accessed every time someone looks at his or her profile. Facebook employs a cache to stop that happening:

Getting to Grips with the Facebook Platform

Of course, at this stage, you’re probably more concerned with just getting the application working—so let’s continue looking at the Platform, but just bear that point in mind.


The Facebook Platform Elements

There are three elements to the Facebook Platform:

  • The Facebook API (Application Programming Interface)
  • FBML—Facebook Markup Language
  • FQL—Facebook Query Language

We’ll now spend some time with each of these elements, and you’ll see how you can use them individually, and in conjunction to make powerful yet simple applications. The great thing is that if you haven’t got your web server set up yet, don’t worry, because Facebook supplies you with all of the tools that you would need in order to do a test run with each of the elements.

The Facebook API

If you’ve already done some programming, then you’ll probably know what an API (or Application Programming Interface) is. It’s a set of software libraries that enable you to work with an application (in this case, Facebook) without knowing anything about its internal workings. All you have to do is obtain the libraries, and start making use of them in your own application.

Now, before you start downloading files, you can actually learn more about their functionality by making use of the Facebook API Test Console.

The Facebook API Test Console

If you want to make use of the Facebook Test Console, you’ll first need to access the Facebook developers’ section—you’ll find a link to this at the bottom of every Facebook page:

Getting to Grips with the Facebook Platform

Alternatively, you can use the URL to go there directly in your browser. When you get to this page, you’ll find a link to the Tools page:

Or, again, you can go directly to, where you’ll find the API Test Console:

Getting to Grips with the Facebook Platform

You’ll find that the API Test Console has a number of fields:

  • User ID—A read-only field which (when you’re logged on to Facebook) unsurprisingly displays your user ID number.
  • Response Format—With this, you can select the type of response that you want, and this can be:
    • XML
    • JSON Facebook
    • PHP Client
  • Callback—If you are using XML or JSON, then you can encapsulate the response in a function.
  • Method—The actual Facebook method that you want to test.

Once you’ve logged in, you’ll see that your User ID is displayed, and that all the drop-downs are enabled:

Getting to Grips with the Facebook Platform

You will also notice that a new link, documentation, appears on the screen, which is very useful. All you have to do is to select a method from the drop-down list, and then click on documentation. Once you’ve done that you’ll see:

  • A description of the method
  • The parameters used by the method
  • An example return XML
  • A description of the expected response.
  • The FQL equivalent (we will discuss this later in the chapter.)
  • Error codes

For now, let’s just change the Response Format to Facebook PHP Client, and then click on Call Method to see what happens:

Getting to Grips with the Facebook Platform

In this case, you can see that the method returns an array of user ids—each one being the ID of one of the friends of the currently logged in user (that is your list of friends because you’re the person logged in). You could, of course, go on to use this array in PHP as part of your application, but don’t worry about that at the moment. For the time being, we’ll just concentrate on working with our prototyping in the test console.

However, before we move on, it’s worth noting that you can obtain an array of friends only for the currently logged in user. You can’t obtain the list of friends for any other user. So, for example, you would not be able to use friends.get on id 286601116 or 705175505. In fact, you wouldn’t be able to use friends.get for 614902533 (as shown in the example) because that’s my ID and not yours.

On the other hand, having obtained a list of valid IDs we can now do something more interesting with them. For example, we can use the users.getinfo method to obtain the first name and birthday for particular users:

Getting to Grips with the Facebook Platform

As you can see, a multidimensional array is returned to your PHP code (if you were actually using this in an application).Therefore, for example, if you were to load the array into a variable $birthdays, then $birthdays[0][birthday] would contain January 27, 1960.

Of course, in the above example, the most important piece of information is the first birthday in the array—record that in your diary for future reference. And, if you’re thinking that I’m old enough to be your father, well, in some cases this is actually true:

Getting to Grips with the Facebook Platform

Now that you’ve come to grips with the API Test console, we can turn our attention to FBML and the FBML Test Console.


Please enter your comment!
Please enter your name here