考拉 - 获得一些帖子的喜欢数量

时间:2013-10-16 17:31:11

标签: ruby-on-rails facebook facebook-graph-api koala koala-gem

我在使用Koala 1.7.0rc1和新的Facebook图表api时遇到了问题。我正在尝试使用此请求[object_id]/likes?summary=1检索帖子的数量。此查询适用于Facebook Graph Explorer,但我无法使用Koala访问“摘要”:

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

2 个答案:

答案 0 :(得分:6)

你应该这样做:

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

Facebook给出的api文档在这里有点误导: https://developers.facebook.com/docs/reference/api/post/

它表示summary = 1应该是summary = true在rails

答案 1 :(得分:5)

您需要从Koala的原始响应中获取摘要数据,如下所示:

likes = graph.get_object("5718732097_10151698726822098/likes?summary=1").
              raw_response["summary"]["total_count"]