Search code examples
ruby-on-railsrubyfacebookfacebook-graph-apikoala

How to get the number of likes of a facebook post using koala gem get_object function


I am trying to use koala gem to retrieve the real like numbers of a Facebook post.

In the Facebook graph explore, I have tried:

5718732097_10151698726822098/likes?summary=1

according to the https://developers.facebook.com/docs/reference/api/post/ page.

This query works and return a hash with a entry:

"summary": { "total_count": 19541 }

So, how could I do this query using koala gem. The main problem is that I do not know how to pass the summary = 1 to the get_object function.

I have tried:

1.likes = graph.get_object("5718732097_10151698726822098", summary: 1){|data| data['likes']}

2.likes = graph.get_object("5718732097_10151698726822098/likes?summary=1")

neither of them works, any one can help? Thanks a lot!

Can any one help me about this?


Solution

  • I just got this answer by myself:

    So I should do

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

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

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