12
12

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.

目的のハッシュタグを含むツイートを取得する

Last updated at Posted at 2015-09-09

Player!は、twitterに同時投稿した際に#playerappがつきます。
そのため、どんな投稿がされているのかなというのが気になったときに、使えるもの書きました。

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

twitter.rb

require "twitter"

# Twitter APIによるリクエスト
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

# 取得するツイートの上限数
limit   = 10

# 欲しいハッシュタグのキーワード
tag = "playerapp"

# ここでツイートを取得
client.search("##{tag}", lang: 'ja', result_type: 'recent', count: 1).take(limit).map do |tweet|
  puts "#{tweet.user.name}: #{tweet.text}"
end

Twitterで指定のusernameのツイートを取得するではなく、こっちが欲しかったやつでした

あと、TwitterのDocumentにサンプルが皆無で心底読みづらかったので、お気をつけください

12
12
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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?