Reputation: 673
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 :)
Upvotes: 0
Views: 617
Reputation: 347
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
Upvotes: 0
Reputation: 86
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
Upvotes: 1