Skip to content
Aug 19 / Scott Phillips

Using the PHP SDK to run FQL queries using the Facebook Graph API

This one took me awhile to figure out for some reason, mainly because they don’t make great mention of it in the switch over from the old api to the new graph api.

So if you’re looking to run a FQL query and you’re using the new PHP SDK for the Graph API, your code should look something like this:

(Obviously you need to add in your id/key.)

$facebook = new Facebook(array(
'appId'  => 'YOUR_API_KEY',
'secret' => 'YOUR_API_SECRET',
'cookie' => true,
));

$fql = "SELECT page_id, name from page where name='Coke'";

$response = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));

print_r($response);

I’ve also seen it done this way as well:

$param  =   array(
'method'    => 'fql.query',
'access_token' => $cookie['access_token'],
'query'     => $fql,
'callback'  => ''
);
$response   =   $facebook->api($param);
print_r($response);

Leave a comment