问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/19057722/get-the-like-count-of-a-public-facebook-photo-via-javascript-possible