My web app builds a batch request to the Facebook graph API. The batch is composed by making a first API call to grab the user’s friends. Then I loop over the list of friends and add a specific request for each (with that user’s specific access token) and add each one to the batch. So it ends up being two API calls. Unfortunately, it’s REALLY slow, and I’ve heard the FQL requests are faster.
So my question is, can I do this with FQL? I’ve read the documentation but I can’t figure out how I might return, for example, all the friends of friends’ work history (which requires each friend’s access token) with one single FQL query. Is this possible? Obviously I could build a batch request of FQL requests, but that would leave me back where I started.
UPDATE:
I’ve done some tests and FQL definitely seems to be faster than a batch request. My FQL multiquery looks like this:
$multiQuery = array(
"query1"=>"SELECT uid2 FROM friend WHERE uid1 = me()", //LIST OF FRIEND IDs
"query2"=>"SELECT uid, name, work, education, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM #query1)", //FRIEND PROFILES
"query3"=>"SELECT uid2 FROM friend WHERE uid1 IN (SELECT uid FROM #query2 WHERE is_app_user=1)",
"query4"=>"SELECT uid, name, work, education FROM user WHERE uid IN (SELECT uid2 FROM #query3)"
);
$multiQueryResult = $facebook->api(array(
'method' => 'fql.multiquery',
'queries' => $multiQuery
));
var_dump( $multiQueryResult );
The query works but there are two problems:
-
query3 returns all the user ids, NOT just the ones who’ve authorized
my app. -
query4 doesn’t return the work/education fields… presumably
because the API request is being called with the current user’s
access token (as opposed to that of specific user from query3). I’ve stored the authorized users’ access tokens in the DB, but I don’t know if it’s possible to use them in this context.
CAN this be done with FQL?? Can I define unique access tokens within an FQL multiquery?
This isn’t really an answer to my original question because there doesn’t appear to be one. It seems that at the time of writing this, the Facebook batch request is just really slow… which is too bad since that basically defeats its entire purpose.