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:
The Facebook Web Application Model
As far as your application users are concerned, they will just access Facebook.com 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:
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:
Different components of the Facebook platform
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:
- 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:
- 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:
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:
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: