2016-03-15 50 views
0

我需要授权这两个范围的对我的谷歌应用程序脚本:授权范围2在谷歌应用程序脚本

https://www.googleapis.com/auth/drive

https://www.googleapis.com/auth/spreadsheets

如何授权两者兼而有之?我目前有以下授权第一个:

OOB_URI = 'urn:ietf:wg:oauth:2.0:oob' 
APPLICATION_NAME = 'My App' 
CLIENT_SECRETS_PATH = 'lib/google_auth.json' 
CREDENTIALS_PATH = File.join(Dir.home, '.credentials', 
          "script-ruby-my-app.yaml") 
SCOPE = 'https://www.googleapis.com/auth/drive' 

def authorize 
    FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH)) 

    client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH) 
    token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH) 
    authorizer = Google::Auth::UserAuthorizer.new(
    client_id, SCOPE, token_store) 
    user_id = 'default' 
    credentials = authorizer.get_credentials(user_id) 
    if credentials.nil? 
    url = authorizer.get_authorization_url(
     base_url: OOB_URI) 
    puts "Open the following URL in the browser and enter the " + 
     "resulting code after authorization" 
    puts url 
    code = gets 
    credentials = authorizer.get_and_store_credentials_from_code(
     user_id: user_id, code: code, base_url: OOB_URI) 
    end 
    credentials 
end 

回答

0

找到它了。 SCOPE可以是一个数组,因此可以通过一次调用来授权多个服务。