I'm having trouble processing Google Spreadsheet with a Powershell script.
I've created a Google Sheet, created a Google Cloud Project, enabled the Sheets & Drive APIs, created a service account, and added it to Google Sheet (shared).
Installed Google Cloud SDK:
Install-Module GoogleCloud
gcloud init
gcloud auth activate-service-account --key-file .\Documents-eb5947bf353a.json
but requesting a value range throws a "403 (Forbidden)" error:
$sheetidDocuments = "XXXXXXXXXXXXXXXXXXXXXXXXX"
$rangeDocuments = "Sheet1!XXX:XXX"
$requestUri = "https://sheets.googleapis.com/v4/spreadsheets/$sheetidDocuments/values/$rangeDocuments"
$result = Invoke-RestMethod -Uri $requestUri -Method Get -ContentType "application/json; charset=utf-8"
and I have no clue why. I lost hours trying to fix it, no success. Is that how service accounts work, or I have to use OAuth2 with access tokens for this?
I just want to read/write to a sheet.
Other projects that use user accounts instead of service accounts work just fine.