Skip to content

Instantly share code, notes, and snippets.

@todesking
Created April 28, 2010 14:49
Show Gist options
  • Save todesking/382237 to your computer and use it in GitHub Desktop.
Save todesking/382237 to your computer and use it in GitHub Desktop.
Register twitter's oauth info to Pit repo
#!/usr/bin/ruby
# this script based on http://d.hatena.ne.jp/shibason/20090802/1249204953
require 'rubygems'
require 'pit'
require 'oauth'
print 'Pit name: '
pit_name=gets.chomp.strip
consumer_info=Pit.get(pit_name,:require=>{
'consumer_key'=>'consumer key',
'consumer_secret'=>'consumer secret'
})
raise 'ERROR: load consumer info failed' if consumer_info.empty?
consumer = OAuth::Consumer.new(
consumer_info['consumer_key'],
consumer_info['consumer_secret'],
:site => 'http://twitter.com'
)
request_token = consumer.get_request_token
puts "Access this URL and approve => #{request_token.authorize_url}"
print "Input OAuth Verifier: "
oauth_verifier = gets.chomp.strip
access_token = request_token.get_access_token(
:oauth_verifier => oauth_verifier
)
Pit.set(pit_name,:data=>Pit.get(pit_name).merge({
'access_token'=>access_token.token,
'access_token_secret'=>access_token.secret
}))
puts 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment