Akhil  Chakicherla
Akhil Chakicherla

Reputation: 47

Google Sheets API - Python - Creating a Sheet

I am new to API's and i am trying to create a google sheet using python. I am able to create google sheet but unable to view/edit(Access issue). I am using Service Account in API's. Please help me in modifying the code to access the created sheets.

Here is the sample code i am using to create one.

service = discovery.build('sheets', 'v4', credentials=credentials)

spreadsheet_body = {
}

request = service.spreadsheets().create(body=spreadsheet_body)
response = request.execute()

Upvotes: 0

Views: 463

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

  • Most likely you are creating the sheet as the service account - by default on its Drive, this is why you have issues accessing it.
  • If instead you want to create a sheet on YOUR drive, you need to use impersonation:

  • After enabling domain-wide delegation, you need to impersonate the service account as you.

  • In python you can do it by specifying credentials = credentials.create_delegated(user_email) when instantiating the service object.

Upvotes: 0

Related Questions