Get list timeline by using Twitter gem

2019-05-22 20:58发布

I want to get list timeline by using Twitter gem.

How can I call GET lists/statuses REST API from Twitter gem? https://dev.twitter.com/docs/api/1.1/get/lists/statuses

I've searched through documentation but couldn't found proper method. http://rdoc.info/gems/twitter

Problem solved I overlooked the method list_timeline. It serves as lists/statuses.

标签: ruby twitter
3条回答
叛逆
2楼-- · 2019-05-22 21:09

To get the timeline from a list using Twitter gem :

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

# For each list of the user
client.lists.each do |list|
  # Get the timeline with the list ID
  client.list_timeline(list.id).each do |tweet|
    puts tweet.text
  end
end
查看更多
贼婆χ
3楼-- · 2019-05-22 21:11

I suggest you start by reading the gem documentation. You'll also have to register your application with twitter to get your oauth parameters.

https://github.com/sferik/twitter

查看更多
Juvenile、少年°
4楼-- · 2019-05-22 21:12

You can use 'twitter' gem.

Create an app on Twitter. You need to give to it read & write access just for sake of your own experiments.

Use this sample code (with your credentials you've got from Twitter). Please note that I'm using some public list URI (list = URI.parse('https://twitter.com/sferik/presidents') p client.list_timeline(list))

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

list = URI.parse('https://twitter.com/sferik/presidents')
client.list_timeline(list)

for more info please visit Twitter gem docs.

查看更多
登录 后发表回答