Monday, June 20, 2011

Facebook Multi Query through PHP SDK

For those of you wondering how to perform Facebook multi query request through Facebook official PHP SDK, here is a quick implementation:

-First create your queries as JSON object (this could be either done through creating an array and then calling json_encode function of php json plugin or you can directly form it as I did in here). Here we want to retrieve the names of family members of a particular user.

$queries = '{
"uids":"select uid from family where profile_id=**********",
"names":"select name from user where uid in (select uid from #uids)"
}';

-Second, you need to create the parameter array as follows:

$param = array(
'method' => 'fql.multiquery',
'queries' => $queries,
'access_token' => $access_token //here you need your own access token
);

-third, call the api function:

$userdata = $facebook->api($param);

-fourth, you are done, no need to do anything else.


It is that easy. This would prevent you from issuing two separate queries.

1 comment: