Skip to content

Instantly share code, notes, and snippets.

@jpmckinney
Last active August 22, 2019 00:29
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jpmckinney/5686265 to your computer and use it in GitHub Desktop.
Download all Twitter list members to CSV
require 'csv'
require 'twitter'
Twitter.configure do |config|
config.consumer_key = ''
config.consumer_secret = ''
config.oauth_token = ''
config.oauth_token_secret = ''
end
def all_list_members(list_owner_username, slug)
users = []
cursor = -1
while cursor.nonzero?
response = Twitter.list_members(list_owner_username, slug, :cursor => cursor)
users += response.users
cursor = response.next_cursor
end
users
end
def all_friends(user)
users = []
cursor = -1
while cursor.nonzero?
response = Twitter.friends(user, :cursor => cursor)
users += response.users
cursor = response.next_cursor
end
users
end
CSV.open('list.csv', 'w') do |csv|
csv << %w(ID Name ScreenName Location Description URL)
all_list_members('verified', 'politics').each do |user|
url = user.attrs[:entities][:url]
csv << [
user.id,
user.screen_name,
user.name,
user.location,
user.description,
url && url[:urls][0][:expanded_url],
]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment