I have created the necessary service account credentials from google cloud console and trying the below code is giving me the error
curl 'https://sheets.googleapis.com/v4/spreadsheets/MySheetID?ranges=A1:B5&key=TheServerKeyIGeneratedInAPIManager'
But this is what it returns:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
To solve this issue, you have to:
- Create a service account: https://console.developers.google.com/iam-admin/serviceaccounts/
- In options, create a key: this key is your usual client_secret.json - use it the same way
- Make the role owner for the service account (Member name = service account ID = service account email ex: myservice-app@appname-202312.iam.gserviceaccount.com
- Copy the email address of your service account = service account ID
- Simply go in your browser to the Google sheet you want to interact with
- Go to SHARE on the top right of your screen
- Go to advanced settings and share it with an email address of your service account ex: myservice-app@appname-202312.iam.gserviceaccount.com