Last active
December 19, 2015 17:49
-
-
Save tsux89/5994496 to your computer and use it in GitHub Desktop.
twitter + ocraの時のテンプレ require > 1.9.3
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
# coding:UTF-8 | |
require 'twitter' | |
require 'oauth' | |
require 'tweetstream' | |
require 'date' | |
require 'launchy' | |
$ck = 'IQKbtAYlXLripLGPWd0HUA' | |
$cs = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU' | |
# Get Access Token | |
oauth = OAuth::Consumer.new( | |
$ck, | |
$cs, | |
site: "https://twitter.com" | |
) | |
request_token = oauth.get_request_token | |
Launchy.open("#{request_token.authorize_url}") | |
pin = gets.chop | |
access_token = request_token.get_access_token( | |
oauth_verifier: pin | |
) | |
$at = access_token.token | |
$ats = access_token.secret | |
# -------------AUTH TWITTER------------- # | |
$host = Twitter::Client.new( | |
:consumer_key => $ck, | |
:consumer_secret => $cs, | |
:oauth_token => $at, | |
:oauth_token_secret => $ats | |
) | |
# -------------------- STREAMING -------------------- # | |
TweetStream.configure do |config| | |
config.consumer_key = $ck | |
config.consumer_secret = $cs | |
config.oauth_token = $at | |
config.oauth_token_secret = $ats | |
config.auth_method = :oauth | |
end | |
client = TweetStream::Client.new | |
client.userstream do |status| | |
# rokiegleの語句がユーザー名に含まれるアカウントにfavoriteされたらスパム報告。 | |
puts "#{status.user.screen_name}: #{status.text}" | |
str = status.text | |
usr = status.user.screen_name | |
client.on_event(:favorite) do |event| | |
if event[:source][:screen_name] =~ /rokiegle/ then | |
$host.report_spam("#{event[:source][:screen_name]}") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment