简体   繁体   中英

Authenticating with google cloud sdk without service account

Running from a local jupyter notebook.

I am trying to do the very simple task of downloading a file from a GCP storage bucket using the following code:

from google.cloud import storage

# Initialise a client
storage_client = storage.Client("gcpkey.json")
# Create a bucket object for our bucket
bucket = storage_client.get_bucket("gcp_bucket")
# Create a blob object from the filepath
blob = bucket.blob("file_in_bucket_I_want.file")
# Download the file to a destination
blob.download_to_filename("destination_file_name")

Importantly I want to use my end-user account and cannot use a service account. I am finding the google docs incredibly confusing. Could someone please tell me where to get the gcp json key and whether it is as simple as the code snippet above or whether I have to add some intermediary steps?

When I follow the linked docs I get sent to an OAuth portal and when I login through google I get this error message:

This app isn't verified
This app hasn't been verified by Google yet. Only proceed if you know and trust the developer.

If you’re the developer, submit a verification request to remove this screen. Learn more

The easiest would be to just run

gcloud auth application-default login

And then in the script just:

storage_client = storage.Client()

And it will get the credentials from the environment.

Alternatively, you can follow this doc to go through the OAuth consent screen and generate a client secret.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM