Last active
January 1, 2016 04:59
-
-
Save Yamabiko/8095811 to your computer and use it in GitHub Desktop.
あるワードを含むツイートを検索して表示するプログラム。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twitter' | |
TW_CONSUMER_KEY = " your consumer key " | |
TW_CONSUMER_SECRET = " your consumer secret " | |
TW_ACCESS_TOKEN = " your access token " | |
TW_ACCESS_TOKEN_SECRET = " your access token secret " | |
# ログイン | |
# ログイン不要な操作もありますがこれやっとけば大抵問題ない(適当 | |
twClient = Twitter::REST::Client.new do |config| | |
config.consumer_key = TW_CONSUMER_KEY | |
config.consumer_secret = TW_CONSUMER_SECRET | |
config.access_token = TW_ACCESS_TOKEN | |
config.access_token_secret = TW_ACCESS_TOKEN_SECRET | |
end | |
word = "update_name" # 検索したいワード | |
# word を含む tweet を 10 件取得する | |
results = twClient.search(word, :count => 10, :result_type => "recent") | |
results.attrs[:statuses].each do |tweet| | |
puts Time.parse(tweet[:created_at]) | |
puts tweet[:id] | |
puts "@" + tweet[:user][:screen_name] | |
puts tweet[:text] | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment