Dropboxのlong-lived access tokensの廃止に対応する

DropboxAPI Updatesに対応する。

Action Required: Token and Permission Updates

こんな内容のメールが来てたので対処する。

long-lived access tokensが使えなくなるようなので、それを何とかしないといけないようだ。

dropbox_uploader.shで使う

こちらのGitHub - andreafabrizi/Dropbox-Uploaderを使っている。

Githubページにアクセスすれば、READMEに該当アップデートのことが載っていた。

Upgrading from old dropbox API

Starting September 30th, 2021, Dropbox is updating their API (OAuth scopes, PKCE, refresh tokens, and short-lived access tokens) dropbox_uploader.sh configurations made with the old API will not longer work after that date. Reconfigure dropbox_uploader.sh:

なるほど。

すること

つまり、

  • 既存の連携を削除して、
  • 設定用ファイル.dropbox_uploaderを削除して、
  • Dropboxで連携用Appを作り直して、権限を設定して、(ここはmigrateでも十分。詳しくは後述
  • dropbox_uploader.shを最新版にして、
  • 連携しなおす。

これらを行えばいいようだ。 以降はこれらを順に説明する。

既存の連携の削除は、Dropboxのアカウントページ→Dropboxから行うことができる。削除自体は引用箇所の通り、日本語ならばリンクを解除を押せばいい。

設定ファイル.dropbox_uploaderは単純に削除する。残しておきたいならリネームでいい。動作の確認が済むまでは、バックアップを取っておくのが吉。

連携用Appの作成は、Dropboxのウェブサイト上で行う。App Console - Dropbox←から行える。 Appを作成した後、権限の付与を忘れないようにしておく。この3つはONにしておいた。

  • files.metadata.write
  • files.content.write
  • files.content.read

ONにした後は設定を保存するのを忘れないように。

最新版にするには、dropbox_uploader.shを置き換えるだけでいいようだ。curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.shで取ってくることが出来る。

連携は、最新版にしたdropbox_uploader.shの初回起動(.dropbox_uploaderが存在しない状態)の過程で行うことが出来る。次のような内容のプロンプトが現れる:

$ ./dropbox_uploader.sh 

 This is the first time you run this script, please follow the instructions:

(note: Dropropbox will change there API from 30.9.2021.
When using dropbox_uploader.sh configured in the past with the old API, have a look at README.md, before continue.)

 1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
 2) Click on "Create App", then select "Choose an API: Scoped Access"
 3) "Choose the type of access you need: App folder"
 4) Enter the "App Name" that you prefer (e.g. MyUploader30475219218811), must be uniqe

 Now, click on the "Create App" button.

 5) Now the new configuration is opened, switch to tab "permissions" and check "files.metadata.read/write" and "files.content.read/write"
 Now, click on the "Submit" button.

 6) Now to tab "settings" and provide the following information:
 App key: <App Key>
 App secret: <App Secret>
  Open the following URL in your Browser and allow suggested permissions: <認証用URL>
 Please provide the access code: <認証用URLのページで認証した後表示されるアクセスコード>

 > App key: <App Key>
 > App secret: '<App Secret>
 > Access code: '<認証した後表示されるアクセスコード>'. Looks ok? [y/N]: y
   The configuration has been saved.

Twitterのと同じ感じだ。以前実装した覚えがある。 ちゃんと読めば権限のことも書いてある。これに従えば問題ない。優しい。

設定ファイルのファイルパスだけは表示してくれるとありがたかった。最後の行あたりに。

全て済み、順調に稼働することが確認できたら、リネームしてバックアップを取っておいたファイルたちもお役御免ということで削除していいだろう。古いバージョンの.dropbox_uploaderdropbox_uploader.shを消す。

おわり・Appの作り直しは不要だったことに気づく

スクリプトが対応してくれていたおかげでだいぶ楽に済んだ。 設定ファイルとスクリプトのバックアップを取って、新しいスクリプトを用意して、再設定するだけでよかった。

ブラウザでログインしているアカウントで紐付けされるので、もし異なるアカウントで連携したいならば注意が必要だと思う。一旦ログアウトしておいたりする必要がありそうだ。

自分の今回の場合は、利用者が自分だけなので作り直しが効いたが、利用者が多いとAppを作り直す方法はまずいだろう。 と思って、古いAppをDropboxのAppConsoleで見ていたら、migrateボタンが下部にあった。これならAppを作り直す必要はない。

古いAppをmigrateするときは、事前に権限を利用に適するものに設定しておく必要がありそうだ。 migrate自体はすぐに終わった。利用は試していないが、App keyなどは変わっているだろうから再設定は必要だと思う。

Dropbox紹介リンク: こちらから登録すると容量アップ(双方+500MB)。懐かしい制度。 まだこういうリンクがあるとは思わなかった。

以上です。


Dropbox関連書の広告

https://amzn.to/3gif60o
タイトルとURLをコピーしました