You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of the world is on Python 3 today, but there are still some with dependencies on 2.x that make migration challenging. The Python code samples in this repo are both Python 2-3 compatible, hence why you don't see newer features like async-await, type annotations, f-strings, etc.
Code samples
The sample apps from the post come in several versions. This table will help you choose which works for you. Be sure to complete the setup & prerequisites below to ensure the samples will run if you haven't already.
Click on Library tab in the left-nav; search for "Drive", and enable
DevConsole link -- You may be new to Google APIs or don't have experience enabling APIs manually in the DevConsole. If this is you...
Check out the API listing page to learn more about the API and enable it from there.
Alternatively, skip the API info and click this link for the enable button.
Command-line (gcloud) -- Those who prefer working in a terminal can enable APIs with a single command in the Cloud Shell or locally on your computer if you installed the Cloud SDK which includes the gcloud command-line tool (CLI) and initialized its use.
If this is you, issue this command to enable the API: gcloud services enable drive.googleapis.com
Confirm all the APIs you've enabled with this command: gcloud services list
Create OAuth client ID & secret credentials and save the file to your local filesystem as client_secret.json. The code samples will not run without this file present.
Install the Google APIs client library:
NodeJS (16+): Create a basic package.json and install required packages with this command:
npm i googleapis @google-cloud/local-auth
Python 2 or 3 (new auth): In your normal or virtualenv environment, run the following command if using the current/new Python auth libraries (most everyone):
Python 2 or 3 (old auth): If you have dependencies on the older Python auth libraries and/or still have old code lying around that do (see warning sidebar below), run this command to ensure you have the latest/last versions of these libraries:
For Python specifically, 2.x means 2.7, and if you're already planning the migration to 3.x, you should definitely not be using anything older than 2.6 (as it's the 1st release with 3.x-compatible features). For 3.x, it should work for nearly all releases, but 3.7 or newer are recommended.
💥 Caveat: oauth2client deprecated
The older Python auth libraries, primarily oauth2client, were deprecated in 2017 in favor of modern replacements. However the newer libraries do not support OAuth token storage, hence why the older *-old.py samples are generally always shorter than their modern equivalents. For now, oauth2client still works, even in maintenance mode, and provides automated, threadsafe, and 2.x/3.x-compatible storage of and access to OAuth2 tokens for users whereas the newer libraries do not (yet).