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.

0 comments