-
-
Save DessertArbiter/ef25f96cb376b03b06912f3990906a0a to your computer and use it in GitHub Desktop.
Download all Twitter list members to CSV
This file contains 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
require 'csv' | |
require 'twitter' | |
@client = Twitter::REST::Client.new 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 = @client.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 = @client.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