2012-06-29 182 views
0

我正在使用koala宝石,如Railscasts episode #361所示。我试图获得给定邮政的所有评论,但Facebook似乎只会回复最近的50条评论。这是Facebook的Graph API的限制还是我做错了什么?Facebook Graph API仅返回50条评论

fb = Koala::Facebook::API.new oauth_token 
post = fb.get_object(id_of_the_post) 
comments = fb.get_object(post['id'])['comments']['data'] 
puts comments.size # prints 50 

回答

4

图表API分页的结果,当大量的职位超过设定的限制(在你的情况50)。

为了访问结果的下一个页面,称之为“next_page”的方法:

comments = fb.get_object(post['id']) 
while comments['comments']['data'].present? 
    # Make operations with your results 
    comments = comments.next_page 
end 

而且,通过查看源可以看到“的get_object”方法接收3个参数:

def get_object(id, args = {}, options = {}) 

这样,您可以将每页帖子提升为尽可能多的帖子:

comments = fb.get_object(post['id'], {:limit => 1000}) 
相关问题