Skip to content

Instantly share code, notes, and snippets.

@ryanwi
Created February 26, 2014 04:08
Show Gist options
  • Save ryanwi/9223342 to your computer and use it in GitHub Desktop.
Save ryanwi/9223342 to your computer and use it in GitHub Desktop.
require 'twitter'
# twitter app keys from dev.twitter.com
KEY = ''
SECRET = ''
TOKEN = ''
TOKEN_SECRET = ''
# Add members in batch
def add_list_members(list_slug, members)
client = Twitter::REST::Client.new do |config|
config.consumer_key = KEY
config.consumer_secret = SECRET
config.access_token = TOKEN
config.access_token_secret = TOKEN_SECRET
end
# get current members of the list to be more efficient about adding
# however this is not necessariliy a cheap call, as it pages uner
# the hood.
current_members = client.list_members(list_slug)
current_screen_names = current_members.to_a.collect{|u| u.screen_name}
# remve anybody already on the list
members_to_add = members - current_screen_names
puts "----------- adding users to list -----------"
puts members_to_add.inspect
members_to_add.each_slice(20) do |slice|
list = client.add_list_members(list_slug, slice)
sleep rand 10
end
end
members = []
list_slug = "slug of your list"
# Pull twitter screen names from source here and populate members array
add_list_members(list_slug, members)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment