Reputation: 1171
I'm using the PHP Facebook SDK and graph API to get all the likes of all of a user's friends. Problem is it's taking quite a while to execute.
Currently I'm getting all the user's friends, then individually looping through each friend and collecting all their likes.
To speed things up, I want to batch every 50 "/user_friend_fbid/likes" requests (but also do paging for these as well).
i.e. this:
foreach (facebookUserFriends($fb_id) as $friend) { //custom func returns friends
facebookUserLikes($friend['id'],$fb_location); //custom func returns all user likes
}
...versus:
$i = 0;
foreach (facebookUserFriends($fb_id) as $friend) {
$queries[$i]['method'] = 'GET';
$queries[$i]['relative_url'] = $friend['id'].'/likes';
if ($i==49) {
batchProcess($queries); //custom func returns all likes (but doesn't do paging)
$i = 0;
}
$i++;
}
TL;DR how do I perform paging within a batch query?
Upvotes: 0
Views: 1102
Reputation: 2019
I would take a breadth-first approach. Queue up the first 50 users 1st batch request, and when the batch is returned, save the data, and then create a new batch from the 50 paging urls returned.
Upvotes: 0
Reputation: 173652
That stuff could get ugly really fast ;-)
Use FQL multi-query instead and save both parties some time: https://developers.facebook.com/docs/reference/rest/fql.multiquery/
See here as well: Facebook New PHP SDK For Graph API - Multi Query
For your case, a single FQL could suffice:
SELECT object_id, user_id FROM like WHERE user_id IN (SELECT uid2 FROM friend WHERE uid1=me())
That finds the likes for my own friends for instance; substitute me()
with something else.
Upvotes: 1