You can follow the Official Instruction provide by google.
You have to create a Google Cloud Project first, and open the Google Workspace API then activate "Google Drive API". Download the JSON file, then you can continue for the following work.
Clone the repo.
cd <workspace_folder>
git clone https://github.com/nick8592/GoogleAPI-Download-File.git
Create environments
cd GoogleAPI-Download-File
conda env create -f environment.yaml
conda activate api
Move credentials.json
file to workspace
folder.
Insure you've renamed your JSON filename to creadentials.json
.
└── <workspace_folder>
└── GoogleAPI-Download-File
├── img_source
├── README.md
├── .gitignore
├── environment.yaml
├── credentials.json <------
└── download_file.py
Find your file's file_id
. Copy shared link.
Paste shared link on new window, the red line words is your file_id
.
Replace <your_file_id>
with your file_id
in download_file.py
.
file_id = '<your_file_id>'
Run download_file.py
python download_file.py
For the first time, you will see the below warning. Following the instruction as below images.
After you press the final continue button. You should see the window shows below information. And if so, then you can close the window. The file should be downloaded at the same time.
The authentication flow has completed. You may close this window.
If download successfully, you can find the file in your GoogleAPI_Download_File
folder, and the terminal should show
>>> File '<your_file_name>' downloaded successfully.
Google Drive API(Python)從 0 開始到從 URL 下載檔案範例
建立 Google Cloud 專案
啟用 Google Workspace API
Python 快速入門導覽課程
下載及匯出檔案
Set up Application Default Credentials