【问题标题】:ruby/rails ruby/rails How can I get all the tweets from Twitter LIST (of users) using the Twitter API?ruby/rails ruby​​/rails 如何使用 Twitter API 从 Twitter LIST(用户)中获取所有推文?
【发布时间】:2018-03-16 02:06:06
【问题描述】:

我想使用 twitter API 从 twitter 列表(用户)中获取所有推文。
我想要一个包含列表中所有推文的 JSON 响应。将解析 JSON 以查找主题标签并创建图表。 我想用 ruby​​/rails 来做。 我无法在 twitter API 中找到搜索列表的方法。 任何见解都值得赞赏。

【问题讨论】:

标签: ruby-on-rails json ruby twitter tweetstream


【解决方案1】:

这就是我最终要做的。在模型中我添加了功能:

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   

如果推文 ID 不存在,我会从列表中获取推文并将它们添加到我的数据库中。
希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2011-04-24
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2014-10-23
    相关资源
    最近更新 更多