Question

I am using Graph API (PHP SDK) to get the count of shares, likes and comments for specific post.

Right now I am sending 3 api requests to get those numbers:

$post = $facebook->api([post_id_here] . '?summary=1', 'get'); // from this I can get number of shares

$likes = $facebook->api([post_id_here] . '/likes?summary=1', 'get');      

$comments = $facebook->api([post_id_here] . '/comments?summary=1', 'get');

My question is, is there a way to get this info by sending only one api request?

I need to reduce the number of api calls because Facebook has a limit for it, and I have an increasing number of posts in database which I update daily.

Batch call is not exactly what I need, since it also counts as separate requests.

Thanks

Was it helpful?

Solution

Yes you can using- fields.

$facebook->api([post_id_here] . '{post-id}?fields=shares,likes,comments', 'get');

Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top