0
votes

I'm trying to retrieve a user's timeline. The api says you can get (at the most) 3,200 tweets. I only seem to know how to get 20 using this code:

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)

Please help me out, Thanks :)

2

2 Answers

1
votes

The user_timeline function lets you specify certain options. What you're looking for is something like

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

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

0
votes

You can do it by setting max_id parameter 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