使用 Ruby 和 Twitter 我可以收集用户的所有时间线吗?

Using Ruby and Twitter can I gather ALL of a user's timeline?

我正在尝试检索用户的时间线。 api 表示您最多可以获得 3,200 条推文。我似乎只知道如何使用此代码获得 20:

def gather_tweets_from(user)
  tweets = []
  file = File.open("tweets_from.txt","w")
  client.user_timeline(user).each { |tweet| 
    file.puts tweet.text
  }
end
gather_tweets_from(user)

请帮帮我, 谢谢:)

user_timeline 函数允许您指定某些选项。你要找的是

client.user_timeline(user, :count => 200).each { |tweet| 
  file.puts tweet.text

http://www.rubydoc.info/gems/twitter/Twitter/REST/Timelines:user_timeline

您可以通过设置 max_id 参数来实现 http://www.rubydoc.info/gems/twitter/Twitter/REST/Timelines

#set max_id to max value
mnid = 999999999999999999
#set number of tweets you want to get 
max_no_tweets = 3500
count = 0
while(count < max_no_tweets)
    #each loop gets 200 tweet
    client.user_timeline('elonmusk', :count => 200, :max_id => mnid).each do |tweet|
        puts(tweet.text) if tweet.is_a?(Twitter::Tweet)
        #to get the next 200 tweet
        mnid = [mnid,tweet.id].min
        count+=1
    end
end