16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/jekyll/commands/gdrive.rb', line 16
def generate_access_token
require "highline/import"
puts "To use data from Google drive:"
puts "Create a new project with Google's Developer Platform:"
puts "https://console.developers.google.com/project"
puts
puts "Go to the project, select APIs & Auth > APIs from left menu"
puts "Pick the 'Drive API' and make sure it's enabled."
puts "Then select APIs & Auth > Credentials from left menu"
puts "Create new OAuth Client ID"
puts "Pick 'Installed Application' and fill out information"
client = Google::APIClient.new(:application_name => "Jekyll GDrive", :application_version => Jekyll::Gdrive::VERSION)
auth = client.authorization
auth.client_id = ask "Enter your Google Drive API Client ID: "
auth.client_secret = ask "Enter your Google Drive API Client Secret: "
auth.scope =
"https://www.googleapis.com/auth/drive " +
"https://docs.google.com/feeds/ " +
"https://docs.googleusercontent.com/ " +
"https://spreadsheets.google.com/feeds/"
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
unless system("open '#{auth.authorization_uri}'")
puts "Open this page in your browser:"
puts auth.authorization_uri
puts
end
auth.code = ask "Enter the authorization code shown in the page: "
auth.fetch_access_token!
puts "OAuth credentials generated"
puts "To access Google Drive data from your Jekyll site"
puts "Set a GDRIVE environment variable"
puts
puts "export GDRIVE=#{auth.client_id}:#{auth.client_secret}:#{auth.refresh_token}"
end
|