Facebook Package Request

I am trying to rewrite multiple 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'); } 

IN

 $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 get error 404. Some of the aliases you requested do not exist, and then a list of all the channel IDs on the wall. When I call only one simple request, I will receive it successfully. Can someone help me and let me know where I have a mistake?

+4
source share
1 answer

Henry Try this with a cycle of up to $ Comments and $ Likes | "This will return comments and comments from post 0 data. For each message, besides this, you need to add a new array. I saw how you are trying to encode an array request, I could never use this method to work; comments and likes exist in a separate table so to speak. "

NOTE. A packet only accepts a maximum of 20 requests, so a request for 999,999 messages in a loop will still only return the first 19 comments / comments, given that the first request is a message.


 $queryProfileFeed = array( array('method' => 'GET', 'relative_url' => '/me/feed?fields=id%26'.$app_access_token.'' 'name' => 'getLnC', 'omit_response_on_success' => false), array('method' => 'GET', 'relative_url' => '/{result=getLnC:$.data.0.id}/comments?fields=id%26offset=0'), array('method' => 'GET', 'relative_url' => '/{result=getLnC:$.data.0.id}/likes?fields=id%26offset=0'), ); $batchResponse = $facebook->api('?batch='.json_encode($queryProfileFeed), 'POST'); /* json decode response for comments */ $Comments = json_decode($batchResponse[1]['body'], true); /* json decode response for likes */ $Likes = json_decode($batchResponse[2]['body'], true); 

I use the above method, but with lots of batch requests to show my wall in my plugins

but I only request the first 2 comments and like it from the first 10 posts. Moreover, it seems that performance degradation and often time out throw errors like "not an exsist alias"

+3
source

Source: https://habr.com/ru/post/1379183/


All Articles