iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📝

Google Sheets API v4: Troubleshooting "Permission Denied" Errors When Writing to Sheets

に公開

TL;DR

When writing with the Google Sheets API or Google Docs API, register the service account's email address in the [Share] settings.

Error occurs when writing with Google Sheets API

When I tried to write to a spreadsheet using the Google Sheets API v4, the following error occurred.

Response
{
  // ...omitted...
  code: "403",
  message: "The caller does not have permission",
  status: "PERMISSION_DENIED"
}

It seems that while reading works fine, writing is not possible.

Solution

After a bit of research, I found the solution here.

https://stackoverflow.com/questions/38949318/google-sheets-api-returns-the-caller-does-not-have-permission-when-using-serve

It seems necessary to register the email address of the service account you are using for API requests via the [Share] button in the upper right corner of the spreadsheet.

The service account's email address can be checked in the IAM section of the GCP Console.

After adding it, I was able to write without any issues. It's reassuring and convenient to be able to check all accounts with access to the spreadsheet in one place.

Discussion