Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Koala - get number of likes for a post

I'm facing an issue using Koala 1.7.0rc1 and the new Facebook graph api. I'm trying to retrieve number of likes for a post using this request [object_id]/likes?summary=1. This query works in Facebook Graph Explorer but I cannot access 'summary' using Koala :

likes = graph.get_object("5718732097_10151698726822098", summary: 1){|data| data['likes']}
# OR
likes = graph.get_object("5718732097_10151698726822098/likes?summary=1")
like image 682
titibouboul Avatar asked Nov 18 '25 06:11

titibouboul


2 Answers

You should do:

graph.get_object(your_post_id, :fields => "likes.summary(true)")

The api documentation that Facebook gave is kind of misleading here: https://developers.facebook.com/docs/reference/api/post/

It says summary = 1 which should be summary = true in rails

like image 180
Runbai Ma Avatar answered Nov 20 '25 20:11

Runbai Ma


You'll need to get the summary data from the raw response in Koala, like so:

likes = graph.get_object("5718732097_10151698726822098/likes?summary=1").
              raw_response["summary"]["total_count"]
like image 31
Alex Scarborough Avatar answered Nov 20 '25 19:11

Alex Scarborough



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!