Get the like count of a public facebook photo via Javascript - Possible?
Asked Answered
J

2

1

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

Jahncke answered 27/9, 2013 at 18:32 Comment(6)
"These are viewable to the public and so it should be possible to get the amount of likes it has via Javascript." not if facebook doesn't let you do it via javascript by not returning proper CORS headers.Morton
What is that array at the bottom of the graph api response named likes?Morton
graph.facebook.com/10151848827816729/likes?limit=25Morton
you should be able to iterate until there are no more likes, counting the number of likes in the array.Morton
@KevinB that is not a good solution. The pictures I am talking about have 10,000+ likes.Jahncke
Right, but if the api doesn't provide another way of obtaining it, you're sol.Morton
B
4

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.

Barbet answered 28/9, 2013 at 11:20 Comment(1)
You are the hero Stackoverflow needs.Jahncke
W
0

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

Wedge answered 27/9, 2013 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.