I wrote a wrapper function for fql because I had performance issues when running multiple graphapi calls, I read that fql is the way to go when you need lots of data from different facebook users.
this is the function in Fb_ignited.php:
public function fb_fql($fqlquery, $multi=false)
{
/**
* This function is a wrapper for fql
*/
if($multi==true){
$fqlmultiquery = '';
foreach($fqlquery as $querykey => $query){
$query = str_replace(' ', '+', $query);
$fqlmultiquery = $fqlmultiquery . '"' . $querykey . '":"' . $query . '",';
}
$fql_multiquery_url = 'https://graph.facebook.com/'
. 'fql?q={' . $fqlmultiquery . '}'
. '&' . $this->CI->facebook->getAccessToken();
$fql_multiquery_result = file_get_contents($fql_multiquery_url);
$fql_obj = json_decode($fql_multiquery_result, true);
}
else{
$fqlquery = str_replace(' ', '+', $fqlquery);
$fql_query_url = 'https://graph.facebook.com/'
. 'fql?q=' . $fqlquery
. '&' . $this->CI->facebook->getAccessToken();
$fql_query_result = file_get_contents($fql_query_url);
$fql_obj = json_decode($fql_query_result, true);
}
//return results of fql multiquery
return $fql_obj;
}
This is sample code for a controller:
// multi fql
$myfqlqueries = array(
'query1' => 'SELECT name FROM user WHERE uid = 4',
'query2' => 'SELECT name FROM user WHERE uid = 4'
);
$fqlmultitest = $this->fb_ignited->fb_fql($myfqlqueries, true);
print_r($fqlmultitest);
// single fgl
$fqltest = $this->fb_ignited->fb_fql('SELECT name FROM user WHERE uid = 4');
print_r($fqltest);
Explanation:
if you want to run a single query use: $this->fb_ignited->fb_fql($my_query)
if you want to run multiple queries use: $this->fb_ignited->fb_fql($my_query_array, true)
NOTE: allow_url_fopen must be true in the server configuration for fql to work.