i am trying to rewrite few requests into one batch request
$posts = $facebook->api('/me/feed?limit=9999999');
for($i = 0; $i < count($posts['data']); $i++)
{
$comments = $facebook->api($posts['data'][$i]['id'].'/comments');
$likes = $facebook->api($posts['data'][$i]['id'].'/likes');
}
Into
$batch = array();
$req = array(
'method' => 'GET',
"name" => "prispevky",
'relative_url' => '/me/feed',
);
$batch[] = json_encode($req);
$req = array(
'method' => 'GET',
'relative_url' => '{result=prispevky:$.data.*.from.id}/comments'
);
$batch[] = json_encode($req);
$req = array(
'method' => 'GET',
'relative_url' => '{result=prispevky:$.data.*.id}/likes'
);
$batch[] = json_encode($req);
$params = array(
'batch' => '[' . implode(',',$batch) . ']'
);
try
{
$info = $facebook->api('/','POST',$params);
print_r($info);
}
catch(FacebookApiException $e) {
error_log($e);
$info = null;
}
But i recieve error 404 Some of the aliases you requested do not exist and then list of all id of feeds on the wall. When i call just one by simple request, i will recieve it succesfully.
Can someone help me and tell where do i have an error?
Henry Try this with loop to $Comments & $Likes
“This will return the Comments and Likes from post data 0. For each post beyond that you have to add a new array. I seen how you are trying to loop the array request, i have never been able to get that method to work since comments and likes exist in a separate table so to speak.”
NOTE: Batch only accepts a max of 20 requests, so requesting 999999 posts to loop will still only return the first 19 set of comment / likes given the first request is the post.
I use the above method but with alot more batch request to show my wall in my plugins
but i only request the first 2 comments and likes from the first 10 posts. More than that seems to degrade performance and often timeout throwing errors like “alias does not exsist”