Upload a file to Google Drive using Python.
- Python 3
- Requests project
python3 -m pip install requests
Download Python source files or clone this repository.
Navigate to https://console.cloud.google.com/ and create a new project.
Find and enable Google Drive API.
Click on Create Credentials. Select Google Drive API. You will be accessing User data.
Add scope https://www.googleapis.com/auth/drive.file. Select Desktop app as an Application type.
Save your credentials with name client_secret.json in the directory of the source files.
Run auth.py:
python3 auth.py
Open the printed URL in a browser and follow the instructions.
Run upload.py:
python3 upload.py [-v] FILE FOLDER_ID
where FILE
is the file to be uploaded
and FOLDER_ID
is the target folder id in Google Drive.