Skip to content

Instantly share code, notes, and snippets.

@djfpaagman
Created March 19, 2012 14:59
Show Gist options
  • Save djfpaagman/2115352 to your computer and use it in GitHub Desktop.
Save djfpaagman/2115352 to your computer and use it in GitHub Desktop.
Automaticly find Twitter users
# encoding: UTF-8
require 'twitter'
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
# input all the names here or grab them from your database or somewhere else.
names = ['Dennis Paagman', 'Springest', 'Github']
names.each do |name|
begin
@twitter = Twitter.user_search(name)
if @twitter
if twitter_user = @twitter.first
puts "#{twitter_user[:name]}: #{twitter_user[:screen_name]}"
# Save your data here, write it to a database or something.
end
end
rescue Twitter::Unauthorized
puts "Not authorized. Please check the Twitter credentials at the top of the script."
break
rescue Twitter::BadRequest => e
puts "Hit rate limit. Continuing scraping at #{e.ratelimit_reset}"
sleep e.retry_after
retry
rescue Exception => e
puts "Something else went wrong:"
puts e.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment