ruby/rails ruby/rails How can I get all the tweets from Twitter LIST (of users) using the Twitter API?

745 views Asked by At

I would like using the twitter API get all the tweets from a twitter list (of users).
I would like to have a JSON response with the all the tweets in the list. Will parse the JSON to look for hashtags and create graphs. I would like to use ruby/rails doing it. I were not able to find in the twitter API a way to search list. Any insight is appreciated.

1

There are 1 answers

0
mamesaye On BEST ANSWER

This is what I end up doing. In the model i added the function:

def self.list_latest()
list = URI.parse('https://twitter.com/USERNAME/LISTNAME')
$client.list_timeline(list).each do |tweet|
  unless exists?(tweet_id: tweet.id)
    create!(
      tweet_id: tweet.id,
      content: tweet.text,
      screen_name: tweet.user.screen_name,
    )
  end
 end 
end   

I get the tweets from my list and add them to my DB if the tweet ID does not exist.
Hope it helps.