Get the like count of a public facebook photo via

2019-06-03 20:07发布

I am working on a script that gets the amount of likes (or comments, shares) a public facebook photo has.

The photo is posted on a page, for example: https://www.facebook.com/photo.php?fbid=10151848827816729. These are viewable to the public and so it should be possible to get the amount of likes it has via Javascript.


Note that the Facebook Graph API does not return the amount of likes it has: https://graph.facebook.com/10151848827816729

2条回答
我命由我不由天
2楼-- · 2019-06-03 20:30

Part of the Oct. 2, 2013 Breaking Changes is:

“/POST_ID/likes update: Apps will be able to retrieve all likes on a post (rather than the first 4 as it is today) through paging. As a result of the functionality update, the like count will be moved to the summary field.

That works for your photo as well, https://developers.facebook.com/tools/explorer?method=GET&path=10151848827816729%3Ffields%3Dlikes.limit(1).summary(1) gives you

"summary": {
  "total_count": 13610
}

as part of the likes structure in the return data. (limit(1) because you are only interested in the overall likes count, so requesting more individual likes would just waste bandwidth – 1 is the minimal amount of actual like data to fetch, using 0 would be the same as no limit and deliver the default first 25 likes.)

Be aware that you have to have the corresponding migration enabled in your app settings for that to work.

查看更多
\"骚年 ilove
3楼-- · 2019-06-03 20:45

To only get the total number of likes for photo or any other FB object you can use following FQL query.

FB.api({ "method": 'fql.query', "query": 'SELECT user_id FROM like WHERE object_id="' + ID OF Photo + '"' } , function(resp) { totalLikes = resp.length; } Grin

Wrong "Like count" in Facebook Album Stream

查看更多
登录 后发表回答