Jul 27
Wednesday
Filed under Social Network
As stated previously articles, the Facebook platform consists of five components: a markup language derived from HTML (Facebook Markup Language), a REST API for treatment communication between Facebook and your application, a SQL-style language for interacting with Facebook data (Facebook Query Language), a scripting language (Facebook JavaScript), and a set of client libraries for different programming languages. I’ll cover these five fundamentals in the following sections.
Facebook Markup Language

Facebook
If you’ve ever developed in ColdFusion or JSTL (or other tag-based programming language), you’ll find working with the platform’s Facebook Markup Language (FBML) very natural. If you’re new to tag-based programming, just reckon of FBML as fancy HTML tags, because each interaction starts and ends with a tag. But, to distinguish between HTML and Facebook commands, you prefix the tags with fb: as you would if you were using multiple DTDs/schemas in XHTML. By using the FBML tag set, Facebook abstracts a lot of complicated code and makes many of the routine procedures nearly effortless. For example, to add a link to your application’s help pages on your dashboard (the navigational tabs that go across the top), you simply need to add the following lines:
<fb:dashboard>
<fb:help href="help.php">Application Help</fb:help>
</fb:dashboard>
REST API Calls
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 helpful bits of code that speed up the enhancement 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.actions provides ways to access Facebook actions.
- facebook.groups provides methods to access information for Facebook groups.
- facebook.photos provides methods to interact with Facebook photos.
Facebook Query Language
The Facebook Query Language (FQL) is a SQL-style language particularly calculated to allow developers to interact with Facebook information. Facebook allows you to interact with nine separate “tables” to query information frankly. You have access to the following:
- user
- friend
- group
- group_member
- event
- event_member
- photo
- album
- phototag
I’ll get into the specifics of the information you have access to in these “tables” later in next article, but suffice to say, 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 collectively.
- 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 wring my name and picture from Facebook, you would write a simple query like so:
SELECT name, pic
FROM user
WHERE uid = 7608007
The previous snippet, when executed by the Facebook platform, 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 7608007. Calls like these are helpful in charitable you granular control of the information you get back from the API.
Facebook JavaScript
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 scrubs (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. If you’re well versed in JavaScript, you’ll pick this up promptly (or perhaps find it maddening). The following is a quick example of how you can grant a modal dialog box to your users:
<a href="#" onclick="new Dialog().showMessage('Dialog', 'This is the help message
for this link');return fake">Show Dialog Box</a>
When processed through the Facebook platform, a user will be shown the modal dialog box represented in Figure 1-1 after clicking the Show Dialog Box hyperlink. Not terrible for a single line of code!
Client Libraries
The Facebook platform provides many tools to access information, but you are responsible
for providing your own business logic through some other language. Facebook facilitates
this through “official” client libraries for both PHP and Java that grant convenient
methods to access the Facebook application. But, not everyone in the universe uses
Java and PHP exclusively. To help the rest of the programmers who want to develop their
own Facebook application, client libraries are available for the following languages:
- ActionScript
- ASP.NET
- ASP (VBScript)
- ColdFusion
- C++
- C#
- D
- Emacs Lisp
- Lisp
- Perl
- PHP (4 and 5)
- Python
- Ruby
- VB .NET
- Windows movable
This complement of languages must take care of just about most developers today. And although these client libraries are not “officially” supported by Facebook (meaning they won’t answer your questions about using them), they are posted by the company with at least some implicit approval of life the “officially unofficial” client libraries. By the way, I’m still waiting for them to include a library for Assembly.