一、注冊
- 訪問 https://www.dropbox.com/register
- 選擇 "個人"
- 如果想免費使用,一定要選擇 “繼續使用2GB的Dropbox Basic 套餐”,如下:
二、在?Dropbox 中?創建app
- 需要去注冊的郵箱中驗證一下郵箱.
- 訪問 https://www.dropbox.com/developers/apps 創建app
- 按下面的配置進行設置, Name your app 是全平臺唯一的,在我們的場景中沒有特別意義,所以隨便起一個唯一的就好
- 在app 的 Permissions里添加權限
- 在 app 的 Settings里設置
三、生成 refresh token
- 1. 瀏覽器中訪問下面的url,將${YOUR_APP_KEY}將成自己的app key.
https://www.dropbox.com/oauth2/authorize?client_id=${YOUR_APP_KEY}&response_type=code&token_access_type=offline
- 2. 訪問后會提示
點 繼續,會提示
點 允許 得到一個 authorization code(下圖中的馬賽克部分),下步中會用到
- 3. 使用 curl 或者 python 腳本 請求 refresh token,將 ${AUTHORIZATION_CODE}, ${YOUR_APP_KEY}, ${YOUR_APP_SECRET} 替換成對應的值。
curl https://api.dropbox.com/oauth2/token -d code=${AUTHORIZATION_CODE} -d grant_type=authorization_code -d client_id=${YOUR_APP_KEY} -d client_secret=${YOUR_APP_SECRET}
發送請求后將得到如下響應, 將 refresh_token 保存
{"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","token_type": "bearer",..."refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","account_id": "xxxxxxxxx","uid": "xxxxxxxx"
}
四、保存相關信息
- DROPBOX_APP_KEY: app key
- DROPBOX_APP_SECRET: app secret
- DROPBOX_REFRESH_TOKEN: refresh token
五、使用?Lewuathe/dropbox-github-action 上傳
- name: Upload file to Dropboxuses: Lewuathe/dropbox-github-action@v1.0.3with:dropbox-app-key: ${{ secrets.DROPBOX_APP_KEY }}dropbox-app-secret: ${{ secrets.DROPBOX_APP_SECRET }}dropbox-refresh-token: ${{ secrets.DROPBOX_REFRESH_TOKEN }}source-path: /path/source-filetarget-path: /path/target-filewrite-mode: "overwrite"