4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

google-api-ruby-clientでrefresh tokenだけ使ってapi叩く方法

Last updated at Posted at 2018-07-29

rubyでGoogleDriveApiをrefresh tokenだけ渡して叩きたい。

公式のサンプルコード等は認証情報をjsonやyamlから読み込む方法しか書いてなくて、refresh token単体で読み込む情報が少なかったのでメモ。

DriveApiを叩くとする。

authorization = Google::Auth::UserRefreshCredentials.new(client_id: ENV['GOOGLE_CLIENT_ID'],
                                                         client_secret: ENV['GOOGLE_CLIENT_SECRET'],
                                                         refresh_token: リフレッシュトークン)

service = Google::Apis::DriveV3::DriveService.new.tap do |me|
  me.authorization = authorization
end

service.list_files(fields: 'next_page_token, files(id, name)')

こんな感じで、認証してapiを叩くことができた。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?