6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Twitterで指定のusernameのツイートを取得する

Posted at

`gem install twitter'としてgemをインストール

twitter.rb
require "twitter"

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "CONSUMER_KEY" # ①
  config.consumer_secret     = "CONSUMER_SECRET" # ①
  config.access_token        = "ACCESS_TOKEN" # ①
  config.access_token_secret = "ACCESS_TOKEN_SECRET" # ①
end

client.user_timeline("②", { count:  } ).each do |timeline|
  tweet = client.status(timeline.id)
  puts tweet.created_at
  puts tweet.text
end

それぞれを説明すると、
① - Twitter Applicationを作り、取得した値を入れてください
② - 取得したいusername(@の後ろの箇所)を入れてください
③ - 取得したいツイートの数を入れてください

本当は、特定のハッシュタグのついた投稿を取得したかったのですが、なんかこっちが先に出来たので投稿

6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?