Created
May 7, 2009 15:04
-
-
Save hoffrocket/108144 to your computer and use it in GitHub Desktop.
converts twitter username and password to oauth access token and secret
This file contains hidden or 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 'rubygems' | |
require 'twitter' | |
require 'mechanize' | |
consumer_token = 'token' | |
consumer_secret = 'secret' | |
twitter_name = ARGV[0] | |
twitter_password = ARGV[1] | |
oauth = Twitter::OAuth.new(consumer_token,consumer_secret); | |
a = WWW::Mechanize.new { |agent| | |
agent.user_agent_alias = 'Mac Safari' | |
} | |
page = a.get( oauth.request_token.authorize_url) | |
form = page.forms.first | |
form['session[username_or_email]'] = twitter_name | |
form['session[password]'] = twitter_password | |
result = a.submit(form) | |
if (result.body.include?('Success!') #result will be your own redirect page (Web Apps) | |
or | |
result.body.include?("You've successfully granted access to")) #twitter success page (APIs) | |
oauth.authorize_from_request(oauth.request_token.token, oauth.request_token.secret) | |
puts "#{twitter_name} has twitter_token=#{oauth.access_token.token}, twitter_secret=#{oauth.access_token.secret}" | |
else | |
puts result.body | |
puts "Failed to authorize #{twitter_name}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment