Facebook API: Getting counts for likes, comments and shares for pages feed
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]/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
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.