Skip to content

Instantly share code, notes, and snippets.

@grigio
Created March 11, 2010 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grigio/329619 to your computer and use it in GitHub Desktop.
Save grigio/329619 to your computer and use it in GitHub Desktop.
# Usage: ruby twitter-oauth-example.rb
require "rubygems"
require "oauth"
require "json"
CONSUMER_KEY = 'fill me'
CONSUMER_SECRET = 'fill me'
ACCESS_TOKEN = '' # don't worry
ACCESS_TOKEN_SECRET = '' # you'll get them!
consumer = OAuth::Consumer.new(
CONSUMER_KEY,
CONSUMER_SECRET,
:site => "http://twitter.com/"
)
request_token = consumer.get_request_token
if ACCESS_TOKEN.empty?
puts "Go to #{request_token.authorize_url}"
print "PIN: "
@access_token = request_token.get_access_token(:oauth_verifier => gets.chomp )
else
@access_token = OAuth::AccessToken.new(consumer, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
end
# Now You can manage your access token until it doesn't expire
me = JSON.parse(@access_token.get('/account/verify_credentials.json').body)
puts "\nHi --> #{me['name']} <--, I'll post a status for you"
puts status = 'Hello from Twitter OAuth Example :P'
@access_token.post('/statuses/update.json', :status => status )
if ACCESS_TOKEN.empty?
puts "Congratulation You got the keys! Paste them in the code so You won't type the PIN again."
puts "ACCESS_TOKEN = '"+@access_token.token+"'"
puts "ACCESS_TOKEN_SECRET = '"+@access_token.secret+"'"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment