Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active April 19, 2018 06:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save komasaru/3e0daa529fe53d0db008c1d4cdbb0a5f to your computer and use it in GitHub Desktop.
Ruby script to get Tumblr access token from consumer key.
#! /usr/local/bin/ruby
# coding: utf-8
# ***************************************
# Tumblr - Access Token, Secret 取得処理
# ***************************************
require 'oauth'
class TumblrAccessToken
SITE_URL = "http://www.tumblr.com"
def get_token
# Consumer 情報入力
print 'Please input CONSUMER KEY : '
cons_key = gets.chomp
print 'Please input CONSUMER SECRET : '
cons_sec = gets.chomp
# Oauth オブジェクト生成
oauth = OAuth::Consumer.new(
cons_key,
cons_sec,
site: SITE_URL
)
# リクエストトークン取得
req_token = oauth.get_request_token(exclude_callback: true)
# OAuth Verifier 取得
puts "Please access this URL : #{req_token.authorize_url}"
# callback 先の URL にある oauth_verifier= のランダムな文字列を貼り付け
print "Please paste the oauth_verifier: "
verifier = gets.chomp
# アクセストークン取得
access_token = req_token.get_access_token(
oauth_verifier: verifier
)
# アクセストークン表示
puts "---"
puts " ACCESS_TOKEN: #{access_token.token}"
puts " ACCESS_TOKEN_SECRET: #{access_token.secret}"
rescue => e
puts "[#{e.class}] #{e.message}"
exit 1
end
end
TumblrAccessToken.new.get_token if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment