Sample FQL Queries
From Facebook Developer Wiki
This article describes some example FQL queries.
Get the uids of all friends of the $app_user who have the application installed:
Get the names of the groups of which u1 is a member:
Get uids of friends of $app_user with birthdays today (where $today is formatted like December 18):
NOTE: The above clearly will not work for three days of the month (first two only for February), such as if $today is 'July 2', anyone's birthday that begins with the string 'July 2' will result in a match (i.e. July 21, July 27, etc). To solve this, you need to set a $todaylength = strlen($today) variable to track the string's length, this will take care of the birthdays without years; to deal with birthdays with years, make another strpos check that "July 2," string, notice the comma. See below code:
See groups' names that u1 shares with u2:
Get pids in range (1,42) from $user_id's albums, sorted by created date:
See the names of all the events that your friends have been invited to:
In PHP, a typical query would look like this (make sure you include facebook.php and lib):
The returned array is multidimensional, so an easy way to get at the data without the foreach loop (assuming you've only pulled one row, that is, using "WHERE uid=$user") would be:
If there are no rows returned (that is, you look for photos of people together but no photos of them exist), the Facebook PHP client returns an empty string. You can check to see if there are any results like this:
