-
-
Save sferik/9630519 to your computer and use it in GitHub Desktop.
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' | |
def twitter_client | |
@twitter_client ||= Twitter::REST::Client.new do |config| | |
config.consumer_key = 'XXXXXX' | |
config.consumer_secret = 'XXXXXX' | |
config.access_token = 'XXXXXX' | |
config.access_token_secret = 'XXXXXX' | |
end | |
end | |
SLICE_SIZE = 100 | |
def fetch_all_friends(twitter_username) | |
CSV.open("#{twitter_username}_friends_list.txt", 'w') do |csv| | |
twitter_client.friend_ids(twitter_username).each_slice(SLICE_SIZE).with_index do |slice, i| | |
twitter_client.users(slice).each_with_index do |f, j| | |
csv << [i * SLICE_SIZE + j + 1, f.name, f.screen_name, f.url, f.followers_count, f.location.gsub(/\n+/, ' '), f.created_at, f.description.gsub(/\n+/, ' '), f.lang, f.time_zone, f.verified, f.profile_image_url, f.website, f.statuses_count, f.profile_background_image_url, f.profile_banner_url] | |
end | |
end | |
end | |
end | |
fetch_all_friends("screen_name_of_twitter_user") |
Hi! What function should I use for fetch all tweets instead of friend_ids() and users()?
Hello, I have changed this code a little to scrape follower_ids, set the slice to 5000, but still hitting api rate limit, any idea how to avoid that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: replace
f.verified
withf.verified?
- the former is a deprecated method in 5.1+