Facebook API Functions and Operators
Although the FQL language isn’t ANSI-SQL complete, it does have some simple operators
and functions to help you work with user data. FQL has boolean operators (AND, OR, and
NOT), comparison operators (=, >, >=, <, <=, <>), and arithmetic operators (+, -, *, and /).
The functions included in FQL, although not exhaustive, allow you to perform some basic
string manipulations. To conserve bandwidth, you can use the concat() function to group
several tuples together:
<?php
$facebook_config['debug'] = false;
$facebook_config['api_key'] = ‘<your_api_key>’;
$facebook_config['secret_key'] = ‘<your_secret_key>’;
require_once(‘<path_to_client_library>/facebook.php’);
$facebook = new Facebook($facebook_config['api_key'],
$facebook_config['secret']);
/**
* Ensure the user has logged on to Facebook
*/
$user = $facebook->require_login();
/**
* Construct the FQL request
*/
$fql = “SELECT concat(first_name, ‘ ‘, last_name)
end_time >= start_time AND
start_time < end_time
I won’t go into the theory behind nested queries, but I will mention that they are very
useful for testing set membership, set comparisons, and set cardinality. And, this expansion
of the REST call serves as a good example for writing your own custom FQL expressions.
You might find that you will need to take some additional processing to make sure your
information is displayed in a specific order. You’ll have to do this with your client
language. For PHP, you need to sort the array and then slice it. Let’s take the following:
<?php
$fql = “SELECT eid, name, location
FROM event
WHERE eid IN (
SELECT eid
FROM event_member
WHERE uid = ‘$user’
)”;
$fql_result = $facebook->api_client->fql_query($fql);
asort($fql_result);
array_slice($fql_result, 0, 5);
?>
The previous passes an FQL query to find events for the current user, sorts the resulting
PHP array, and returns the array with the six elements (positions 0–5) of the query result.
FQL allows you as a developer to have granular control of the information that you
retrieve about your users from the Facebook servers. Although it’s not as robust as you
might sometimes need (or want) it to be, you can generally get around FQL’s limitations
with some post-processing in the language in which you’re developing. Additionally, as the
complexity of your FQL increases with subqueries, you might at some point run into
problems. As I’ve mentioned earlier, using the Facebook API Test Console at
http://developer.facebook.com/tools.php is a great place to help debug your code. For
instance, if you take the previous query and take out the WHERE clause so that your FQL
statement reads as follows:
SELECT eid, name, location
FROM event
WHERE eid IN (
SELECT eid
JavaScript is stripped from your code. For instance, you cannot use the onclick attribute in
the anchor (<a>) tag to call JavaScript:
<p>
<a href=”javascript:alert(‘You\’ll never see me’);”>click me</a>
</p>
Although completely valid HTML and JavaScript, the previous will raise an error
(shown in Figure 3-3) when your users look at the page containing this code.
Figure 3-3. Facebook errors
Don’t worry, if you need access to JavaScript for your application, Facebook has
developed FBJS, which will allow you to use many of the conventions you typically see in
JavaScript.
When working with FBML, remember that it’s not exactly HTML, even though you use
a lot of the same syntax. Your code has to be processed through the Facebook platform to
ultimately generate the HTML that gets rendered to the user, so not everything you’re used
to doing with HTML code will work.
Blog search terms:
- facebook api function list
- facebook api operators
- fql compare start_time
- fql functions
- fql list operators
- event_member fql
- fql not operator
- function fql list
- list of fql functions
- facebook nested fql issues
- facebook fql operators
- facebook fql list of functions
- facebook fql functions
- facebook fql concat
- facebook api functions list
- facebook api @ operators
- facebok fql subquery in select
- php facebook api
Tags: facebook fan page —