Skip to content

Instantly share code, notes, and snippets.

@QB
Created July 3, 2014 08:46
Show Gist options
  • Save QB/73967daed7505af1fb4c to your computer and use it in GitHub Desktop.
Save QB/73967daed7505af1fb4c to your computer and use it in GitHub Desktop.
新しいアカウントでフォローしなおすスクリプト。 u3, u4, u5 と追加していけば複数のアカウントで同時にフォローをかけることも可能。
require "twitter"
require "json"
USER1 = "account1" # もとのアカウント
USER2 = "account2" # 新しいアカウント
TOKEN_FILE = "twitter-token-list.json"
class FollowController
def initialize(token)
@client = Twitter::REST::Client.new do |config|
config.consumer_key = token["consumer_key"]
config.consumer_secret = token["consumer_secret"]
config.access_token = token["oauth_token"]
config.access_token_secret = token["oauth_token_secret"]
end
end
def friends
friends_list = Array.new
@client.friends.to_a.each do |f|
friends_list.push(f.id)
end
return friends_list
end
def follow(list)
@client.follow(list)
end
end
open(TOKEN_FILE) do |io|
TOKEN = JSON.load(io)
end
u1 = FollowController.new(TOKEN[USER1])
u2 = FollowController.new(TOKEN[USER2])
u2.follow(u1.friends)
# u3 = FollowController.new(TOKEN[USER3])
# u3.follow(u1.friends)
# なんて感じで増やすことも
{
"account1": {
"consumer_key": "YOUR_CONSUMER_KEY",
"consumer_secret": "YOUR_CONSUMER_SECRET",
"oauth_token": "YOUR_ACCESS_TOKEN",
"oauth_token_secret": "YOUR_ACCESS_TOKEN_SECRET"
},
"account2": {
"consumer_key": "YOUR_CONSUMER_KEY",
"consumer_secret": "YOUR_CONSUMER_SECRET",
"oauth_token": "YOUR_ACCESS_TOKEN",
"oauth_token_secret": "YOUR_ACCESS_TOKEN_SECRET"
},
"account3": {
"consumer_key": "YOUR_CONSUMER_KEY",
"consumer_secret": "YOUR_CONSUMER_SECRET",
"oauth_token": "YOUR_ACCESS_TOKEN",
"oauth_token_secret": "YOUR_ACCESS_TOKEN_SECRET"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment