Last active
December 23, 2015 02:39
-
-
Save komasaru/6568377 to your computer and use it in GitHub Desktop.
Ruby script testing to get tweets by tweetstream.
This file contains 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 'tweetstream' | |
# Consumer key, Secretの設定 | |
CONSUMER_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
CONSUMER_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
# Access Token Key, Secretの設定 | |
ACCESS_TOKEN_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
ACCESS_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
# 設定 | |
TweetStream.configure do |config| | |
config.consumer_key = CONSUMER_KEY | |
config.consumer_secret = CONSUMER_SECRET | |
config.oauth_token = ACCESS_TOKEN_KEY | |
config.oauth_token_secret = ACCESS_SECRET | |
config.auth_method = :oauth | |
end | |
# sample 取得 ( 全ツイートからランダムに抽出されたツイートを取得 ) | |
TweetStream::Client.new.sample do |status| | |
puts "#{status.user.screen_name}: #{status.text}" | |
end | |
# 言語設定が「日本語」で、リツイート以外のツイートを抽出 | |
# TweetStream::Client.new.sample do |status| | |
# if status.user.lang == "ja" && !status.text.index("RT") | |
# puts "#{status.user.screen_name}: #{status.text}" | |
# end | |
# end | |
# キーワードで取得 (OR条件) ( 言語設定「日本語」、リツイート以外のツイートを抽出 ) | |
# TweetStream::Client.new.track('tokyo', 'FM') do |status| | |
# if status.user.lang == "ja" && !status.text.index("RT") | |
# puts "#{status.user.screen_name}: #{status.text}" | |
# end | |
# end | |
# 自分のタイムライン(フォローしているアカウント)を取得 | |
# TweetStream::Client.new.userstream do |status| | |
# puts "#{status.user.screen_name}: #{status.text}" | |
# end | |
# 特定のアカウントのツイート、ツイート文内に特定のアカウントを含むツイートを取得 (OR条件) | |
# TweetStream::Client.new.follow(783214, 7080152) do |status| | |
# puts "#{status.user.screen_name}: #{status.text}" | |
# end | |
# 指定件数表示したら終了 | |
# @statuses = [] | |
# TweetStream::Client.new.sample do |status, client| | |
# puts "#{status.user.screen_name}: #{status.text}" | |
# @statuses << status | |
# client.stop if @statuses.size >= 10 | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment