Skip to content

Instantly share code, notes, and snippets.

@shouya
Last active August 16, 2016 00:29
Show Gist options
  • Save shouya/122e67a34712999916ca to your computer and use it in GitHub Desktop.
Save shouya/122e67a34712999916ca to your computer and use it in GitHub Desktop.
twitter oauth
#!/usr/bin/env ruby
# license: WTFPL
# Gems:
# $ gem install twitter twitter_oauth
require 'twitter'
require 'twitter_oauth'
# CONSUMER_KEY = '3nVuSoBZnx6U4vzUxf5w'
# CONSUMER_SECRET = 'Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys'
CONSUMER_KEY = 'IQKbtAYlXLripLGPWd0HUA'
CONSUMER_SECRET = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU'
@access_token = nil
@access_secret = nil
def oauth
return unless @access_key.nil? and @access_secret.nil?
client = TwitterOAuth::Client.new(
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET
)
req_tok = client.request_token
puts "Access the url below to authorize this api"
puts req_tok.authorize_url
print "[ENTER THE CODE]: "
code = gets.strip
access = client.authorize(
req_tok.token,
req_tok.secret,
:oauth_verifier => code
)
@access_token = access.token
@access_secret = access.secret
puts "ACCESS_TOKEN:\t\t#{@access_token}"
puts "ACCESS_TOKEN_SECRET:\t#{@access_secret}"
end
oauth
@client = Twitter::REST::Client.new do |c|
c.consumer_key = CONSUMER_KEY
c.consumer_secret = CONSUMER_SECRET
c.access_token = @access_token
c.access_token_secret = @access_secret
end
@client.update('test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment