Ruby on Rails:如何使用Twitter搜索Api从next_page获取推文? 什么应该是我的since_id和max_id?

这是我的代码。 我试图用@second_results获得下一页的结果。 但它似乎只是重复从@first_results收到的任何内容。

 search = TwitterManualSearch.new @first_results = search.first_query(:tag => params[:search]).results @second_results = search.second_query(:tag => params[:search], :since_id => @first_results.results.last.id, :max_id => @first_results.max_id).results 

为了您的参考,我写了一些方法来缓解调用,我在这里使用twitter gem – https://github.com/sferik/twitter

我知道我在做一些根本错误的事情,但它是什么?

更新:给你一个简短,粗略和快速的想法,这是我如何使用代码返回结果(不包括我的所有方法)

为了获得第一批结果,我做了

 @first_results = Twitter.search("#tag", :count => 30, :result_type => "recent") @first_results.results.map do |status| "#{status.from_user}: #{status.text}" end 

然后再获得更多结果

  @second_results = search.second_query("#tag", :count => 30, :result_type => "recent", :since_id => @first_results.results.last.id, :max_id => @first_results.max_id).results @second_results.map do |status| "#{status.from_user}: #{status.text}" end 

谢谢

阅读https://dev.twitter.com/docs/working-with-timelines 。 你在做什么并不能区分第一个实例变量和第二个实例变量。 相反,只需确保对第一个变量调用进行计数,并将第二个调用的max_id与第一个实例变量调用的最后一个id匹配。 像这样的东西

 @second_results = search.second_query(:tag => params[:search], :max_id => @first_results.results.last.id).results 

而你应该没事。 虽然要注意裁员。

如果您在控制器中执行此操作,最终将从Twitter返回“To many API Calls”错误。 您需要创建一个rake任务,以不超过其速率限制的方式提取所有需要的推文。

https://dev.twitter.com/docs/rate-limiting/1.1

我猜你所看到的可能是超出限制的结果。