Created
April 21, 2013 04:20
-
-
Save QB/5428474 to your computer and use it in GitHub Desktop.
token.json にトークンを沢山突っ込むと、複垢処理を自動でやってくれる。
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 "pp" | |
require "json" | |
require "twitter" | |
require "user_stream" | |
# twitter ジェムと userstream ジェムを使いたいとき | |
# | |
# token.json にトークンを沢山突っ込むと、複垢処理を自動でやってくれる。 | |
# | |
# 使い方(sample.rb というプログラムを書く場合) | |
# 1. token.json にトークンを書き並べる | |
# | |
# { | |
# "screen_name1": { | |
# "consumer_key": "", | |
# "consumer_secret": "", | |
# "oauth_token": "", | |
# "oauth_token_secret": "" | |
# }, | |
# "screen_name2": { | |
# "consumer_key": "", | |
# "consumer_secret": "", | |
# "oauth_token": "", | |
# "oauth_token_secret": "" | |
# } | |
# } | |
# | |
# 2. sample.rb の一番最初に require "./multiple_twitter.rb" と書いて読み込む。 | |
# | |
# トークン突っ込むのは、このプログラムが勝手にやってくれる。 | |
# sample.rb を実行すると、このプログラムが読み込まれて、最初に「どのユーザ(トークン)で起動するの?」と訊かれるので、ユーザ名を答えれば良い。 | |
# | |
open("token.json") do |io| | |
@token = JSON.load(io) | |
end | |
$bar = "\n=========\n" | |
print $bar | |
user_list = @token.keys | |
print user_list | |
print $bar + "上の#{user_list.length}個のアカウントが登録されてるお。どのユーザで起動するの?:;(∩´﹏`∩);:\n>> " | |
user = STDIN.gets.chomp | |
if user_list.include? user then | |
print "よぉし、パパログインしちゃうぞ..." | |
else | |
print "そのユーザ、無さぽよ…(´・ω・`)\n" | |
exit(1) | |
end | |
UserStream.configure do |config| | |
config.consumer_key = @token[user]["consumer_key"] | |
config.consumer_secret = @token[user]["consumer_secret"] | |
config.oauth_token = @token[user]["oauth_token"] | |
config.oauth_token_secret = @token[user]["oauth_token_secret"] | |
end | |
Twitter.configure do |config| | |
config.consumer_key = @token[user]["consumer_key"] | |
config.consumer_secret = @token[user]["consumer_secret"] | |
config.oauth_token = @token[user]["oauth_token"] | |
config.oauth_token_secret = @token[user]["oauth_token_secret"] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment