0

这是我的代码。我正在尝试使用@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

谢谢

4

2 回答 2

1

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

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

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

于 2013-03-31T20:58:35.080 回答
1

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

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

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

于 2013-03-31T21:38:20.873 回答