Facebook API- Getting counts for likes, comments and shares for pages feed

Thursday, 8 January 2015

By default when you request a page’s feed from the Facebook API via /v2.2/[pageid]/feed a lot a JSON is sent back, including very specific data about likes and comment such as who, what, when, etc. However the actual number of likes or comments for that status is not included. There are API endpoints to hit to get this data on a status by status basis (/v2.2/[status_id]/likes?summary=true and /v2.2/[status_id]/comments?summary=true), however that means making two additional calls for each status. Not ideal.

To get this data into the feed endpoint request you need to specify the fields you want to return and then state that you want summary to be returned as well

https://graph.facebook.com/v2.2/[page_id]/feed?fields=id,message,picture,link,shares,created_time,comments.limit(1).summary(true),likes.limit(1).summary(true)&access_token=[YOUR_ACCESS_TOKEN]

You’ll notice that I’ve included limit(1), for both comments and likes. For the project I am working on I am not interested in the actual content of the comments for the moment, I just need to the raw number. Ideally it would be set to 0, however then the API won’t return the summary.

Post changelog

Back to all posts