Created
January 6, 2016 11:22
-
-
Save holysugar/19a597668ac795761e31 to your computer and use it in GitHub Desktop.
fetch google api refresh token
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/bin/ruby | |
require 'jwt' # oops... | |
gem 'google-api-client', '0.8.6' | |
require 'google/api_client' | |
scope = [ | |
'https://www.googleapis.com/auth/drive', | |
'https://spreadsheets.google.com/feeds/', | |
] | |
client_id = ARGV[0] || fail("set client_id") | |
print "input client_secret: " | |
client_secret = $stdin.readline.strip | |
puts | |
client = Google::APIClient.new( | |
:application_name => 'fetch-refresh-token.rb', | |
:application_version => '1.0.0' | |
) | |
auth = client.authorization | |
auth.client_id = client_id | |
auth.client_secret = client_secret | |
auth.scope = scope | |
auth.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' | |
$stderr.print("\n1. Open this page:\n%s\n\n" % auth.authorization_uri) | |
system(%[open "#{auth.authorization_uri}"]) | |
$stderr.print('2. Enter the authorization code shown in the page: ') | |
auth.code = $stdin.gets.chomp | |
auth.fetch_access_token! | |
puts | |
puts "refresh_token: #{auth.refresh_token}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment