2014-09-05 78 views
0

我想爲安裝的應用程序獲得一個純命令行oauth流程,並且將它們拼接在一起並不容易...文檔嚴重缺乏...我開始使用驅動器示例(https://github.com/google/google-api-ruby-client-samples/tree/master/drive),但是當它到達client.authorization = flow.authorize(file_storage)它試圖啓動webrick來建立一個網頁。我需要一些與google提供的CLI工具類似的工具:它需要打印出我需要訪問的URL,然後在響應中閱讀我可以複製&粘貼。這可能與谷歌紅寶石客戶端?是否有安裝應用程序的純命令行oauth流?

回答

1

如下所示猴子補丁作品:

module Google 
    class APIClient 
    class InstalledAppFlow 
     def authorize_cli(storage) 
     puts "Please visit: #{@authorization.authorization_uri.to_s}" 
     printf "Enter the code: code=" 
     code = gets 
     @authorization.code = code 
     @authorization.fetch_access_token! 
     if @authorization.access_token 
      if storage.respond_to?(:write_credentials) 
      storage.write_credentials(@authorization) 
      end 
      @authorization 
     else 
      nil 
     end 
     end 
    end 
    end 
end 
相關問題