Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Twitterのリストに人を登録するRubyスクリプト

More than 5 years have passed since last update.

Twitterのリストに人を登録するのがめんどくさかったので作りました。
@マーク抜きでアカウント名を列挙したファイルを作れば一発で登録できます。

import_twilist.rb
#!/usr/bin/env ruby

require 'twitter'
require 'yaml'

if ARGV[0].nil?
  file = 'members.txt'
  unless File.exists?(file)
    puts "No members file: #{file}"
    exit
  end
  members = Array.new
  File.open(file).each do |line|
    members << line.chomp
  end
else
  members = ARGV
end

twitter_config = YAML.load_file('config.yml')

Twitter.configure do |config|
  config.consumer_key = twitter_config[:consumer_key] 
  config.consumer_secret = twitter_config[:consumer_secret]
  config.oauth_token = twitter_config[:oauth_token]
  config.oauth_token_secret = twitter_config[:oauth_token_secret]
end

begin
  before_list = Twitter.list(twitter_config[:username], twitter_config[:list_name])
  sleep 1
  list = Twitter.list_add_members(twitter_config[:user_name], twitter_config[:list_name], members)
  puts "List: #{list.full_name}"
  puts "Members: #{list.member_count}"
  if (list.member_count - before_list.member_count) < members.size
    puts "Warning: Some user{s} fail add to list..." 
  end
rescue => ex
  puts ex.message
  raise ex
end
config.yml
:user_name: YOUR NAME
:list_name: LIST NAME
:consumer_key: CONSUMER KEY
:consumer_secret: CONSUMER SECRET
:oauth_token: ACCESS TOKEN
:oauth_token_secret: ACCESS SECRET TOKEN
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away