Skip to content

Instantly share code, notes, and snippets.

@nog
Created January 22, 2011 16:59
Show Gist options
  • Save nog/791246 to your computer and use it in GitHub Desktop.
Save nog/791246 to your computer and use it in GitHub Desktop.
twitterのoauthトークンを取得するためだけのプログラム。
#!/usr/bin/env ruby
# coding: utf-8
# via: http://d.hatena.ne.jp/shibason/20090802/1249204953
# 上記ブログで使われてるスクリプト参考にスクリプト自体書き換えなくても、ConsumerKeyとConsumerSecretを聞いてくれるように変えた。
# 一つのアプリの認証キーいっぱい取りたいなら元のスクリプトの方が便利で、複数のアプリのキーいっぱい取りたいならこっちの方が便利。
require 'rubygems'
require 'oauth'
print "Input OAuth Consumer Key: "
consumer_key = gets.chomp.strip
print "Input OAuth Consumer Secret: "
consumer_secret = gets.chomp.strip
consumer = OAuth::Consumer.new(
consumer_key,
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
)
puts "Access token: #{access_token.token}"
puts "Access token secret: #{access_token.secret}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment