I won't repeat it all here: "Application Default Credentials provide a simple way to get authorization credentials for use calling Google APIs."
If you can use Application Default Credentials, do.
There is an extra step you will need to perform the before first using Application Default Credentials as your identity when calling APIs from your machine:
gcloud auth application-default login [[email protected]]
Here's why you'll prefer to use Application Default Credentials:
scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(scopes)
In truth, you can generally get away with just:
credentials = GoogleCredentials.get_application_default()
...That's all the code you need to authorize calls to (any) Google Cloud API!
We'll use the credential
object in the next step to make calls against the Google service...