Python script running on GAE(App Engine) can read a Google Sheet without credentials

Consider a python script running on App Engine, is it possible to access particular Google Sheet that has been shared with app engine default service account of that GCP project where the python scrip is deployed.

Is it possible to build the service endpoint for Google Sheets API

service = build('sheets', 'v4', credentials=creds) # without passing credentials parameter explicitly

without passing credentials file explicitly, is it possible for App Engine app(python script) to take default App Engine service account implicitly(like it dose for Cloud services)    

0 1 432
1 REPLY 1

Hello,

 

Set the environment variable “GOOGLE_APPLICATION_CREDENTIALS” and share the sheet with the app engine default service account. After setting the environment variable, you don't need to explicitly specify your credentials in code when using a Google Cloud client library. The client library can determine your credentials implicitly..

 

Example:

 

import os

 

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="key.json” 

 

service = discovery.build("sheets","v4")

 

I hope this answers your question.

 

[1]https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable

[2]https://stackoverflow.com/questions/64937670/accessing-google-sheets-api-from-google-compute-engine-...