0

インストールされたアプリの純粋なコマンド ライン oauth フローを取得しようとしていますが、これをまとめるのは簡単ではありません... ドキュメントがひどく不足しています... ドライブの例から始めました ( https://github.com/google /google-api-ruby-client-samples/tree/master/drive ) にclient.authorization = flow.authorize(file_storage)到達すると、Webrick を起動して Web ページを作成しようとします。Google が提供する CLI ツールと同様に機能するものが必要です。アクセスする必要がある URL を出力し、コピーして貼り付けることができる応答を読み取る必要があります。これはGoogle Rubyクライアントで可能ですか?

4

1 に答える 1

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
于 2014-09-05T22:48:37.407 に答える