Last active
April 19, 2018 06:39
Star
You must be signed in to star a gist
Ruby script to get Tumblr access token from consumer key.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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