iTranslated by AI
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.
{
// ...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.
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