Material taken from Quickstart for the Google Drive API v3:
"Google Drive for Developers v3: Python Quickstart". Google Developers, https://developers.google.com/drive/api/v3/quickstart/python, retrieved 27 August 2021.
Original contents licensed by Google under a Creative Commons Attribution 4.0 license and code samples under the Apache 2.0 license.
- Sign into the Google Cloud Console.
- Create a new project.
- Enable the Google Drive API for the project.
- Configure the OAuth consent screen.
- Generate credentials.
- Run script.
User Type. If using a personal Google account rather than a Google Workspace (GSuite) account, the app must be configured as External. The Google Developer tutorial assumes that you are using a Google Workspace account, and so proceeds to configure for an Internal app.
App Information. Provide the name of the app and your e-mail for "User support email". At one time, you could avoid Google verification by omitting a logo, but the sensitive scopes enabled below will make verification necessary in any event.
App Domain. Leave blank unless you are using a Google Workspace account.
Developer Contact Information. Provide your e-mail.
Scopes. Add the following scopes:
- Google Drive API /auth/drive.metadata.readonly
- Google Drive API /auth/drive
Both the above scopes are categorized by Google as "sensitive", requiring verification of your app if you choose to publish.
Test Users. Add your account as a test user.
Application type. Desktop app.
Name. Whatever sounds good to you.
After generating the credentials, click on the download icon all the way to the right and save as "credentials.json" in the project folder on your computer. This file should be kept secret from the world, so if your files are being tracked by git be sure to add "credentials.json" and "token.json" (the latter will be created by the script and will contain a copy of these credentials) to the .gitignore file for the project.
Unless you're going to put your code into... production, you can leave its Publishing status at "Test". External apps that are published with scopes classified as sensitive muse be verified by Google.
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
In his tutorial on the Google Drive API, Jonathan Meier configures for a personal Google account. Jonathan Meier. "How to Query Google Drive API in Python". YouTube, 13 June 2020, https://youtu.be/10ANOSssdCw. I have also included his script here (renamed to "listfiles.py") because it demonstrates an alternative pattern for structuring the code. In his 11 minute video, which I highly recommend, Jonathan does a terrific job of explaining the how this all works.
Some more examples, with code reflected in list_gdrive.py, etc., can be found here:
Abdou Rockikz. "How to Use Google Drive API in Python". PythonCode, https://www.thepythoncode.com/article/using-google-drive--api-in-python, Retrieved 30 August 2021.