I am developing a facebook app with PHP (SDK v5). I need to get the posts of a page in which the user has admin privilleges and for each post to count it's likes/comments/shares.
Using the Graph API i ended up with this solution:
$fb = new Facebook\Facebook([
'app_id' => 'XXX',
'app_secret' => 'XXX',
'default_graph_version' => 'v2.7',]);
$pageId = //find the page id
$accessToken = //and the access token
$response = $fb->get('/'.$pageId.'/feed', (string) $accessToken);
$response = $response->getDecodedBody();
$pagePosts = $response['data'];
foreach ($pagePosts as $post) {
//query for the likes and count them
$likesResponse = $fb->get('/'.$post['id'].'/likes', (string) $accessToken);
$likesObject = $likesResponse->getDecodedBody();
echo 'likes count: '.count($likesObject['data']).'<br>';
//comments and shares similar to likes
}
I think that the solution above is far from perfect since for every facebook post three additional calls will be executed (likes, comment, shares). The performance and sclability of this is terrible.
Now for a performance boost, i was planning to use FQL but i stumbled uppon this comment from the facebook FQL documentation:
As of August 8, 2016, FQL will no longer be available and cannot be queried.
So my question is:
Does anyone know another way to retrieve likes/comments/shares efficiently, or even a way to improve the performance of the curent solution?
/feedsendpoint; see syntax example here, stackoverflow.com/a/36479531/1427878 The loop should become unnecessary. Use Graph API Explorer to try & test stuff before putting it into code, developers.facebook.com/tools/explorer - CBroe