LoginSignup
7
9

More than 3 years have passed since last update.

Google driveをCUIで操作できるgdriveが急に死亡したので…

Last updated at Posted at 2020-01-14

GitHub公開の本体ではOAuth認証が通らない。

急にってなったから困る

何が問題?

配布本体のOAuth認証が(多分)古くなっている事から起きている問題です。
なので、自分でOAuth認証(1.client_id 2.client_secret)を用意して、置換してやれば再び動きます。

用いた解決策

参考した解決法

以下原文。

  1. Set up OAuth:
    • Visit the Google Cloud Console
    • Go to the OAuth Consent tab, fill it, and save.
    • Go to the Credentials tab and click Create Credentials -> OAuth Client ID
    • Choose Other and Create.
    • Use the download button to download your credentials.
    • Credentialsタブの画面に(1.client_id 2.client_secret)があるので、特に落とす必要はない
    • Now you have both client ID and client secret in this credential file in the following form:
      • ↓ は落としたJSONの中身
{"installed":{"client_id": <your client id>,"project_id":"i-m-sky-bot","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret": <your client secret>,"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

2、Enable the Drive API:

  • Visit the Google API Library page.
  • Search for Drive. ←ここ謎だったけど
      • ↑を選んで、有効化しろ!って事
      • 一瞬 1.で作ったOAuthプロジェクトが現れるのかな?って深読みして焦った
  • Make sure that it's enabled. Enable it if not.

3、Now you just need to edit the binary and insert your credentials instead of the one hard coded : -

$ sed -i "s|367116221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com|<your client id>|g" path/to/the/executable/gdrive

$ sed -i "s|1qsNodXNaWq1mQuBjUjmvhoO|<your client secret>|g" path/to/the/executable/gdrive

Windowsの悲しみ

尚、Win10では sed(置換コマンド) は使えねぇのでバイナリ書き換えにはStirling_v131を使用
一応PowerShellで↓を使えばいいはずなんだけど、エラったので…

$data=Get-Content .\test.txt | % { $_ -replace "置換する文字列","置換後の文字列" }
$data | Out-File .\test.txt -Encoding UTF8

Google Cloud ConsoleのOAuth Consentに詳しい人教えて!


OAuth何日持つか知らないんだよねぇ…一応30日に設定したけど、意味あるのかな?
その辺どうなんだろうね

7
9
2

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
7
9