Andrey Helldar
Andrey Helldar

Reputation: 161

Google Sheets API: The caller does not have permission

I'm trying to read the document from the cron:

https://sheets.googleapis.com/v4/spreadsheets/<sheet_id>?key=<api_key>

My document is available to anyone with the link.


My #1 key settings:    
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - I added my external IP address.
 - API restrictions - none

My #2 key settings:
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - I added my external IP address.
 - API restrictions - Google Sheets API

My #3 key settings:
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - I added my external IP address.
 - API restrictions - Google Sheets API, Google Drive API

My #4 key settings:
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - none
 - API restrictions - Google Sheets API

My #5 key settings:
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - none
 - API restrictions - Google Sheets API, Google Drive API

My #6 key settings:
Application restrictions:

 - IP addresses (web servers, cron jobs, etc.) - none
 - API restrictions - none

When I try to open a document with each key, I get a 403 error:

{
  "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "status": "PERMISSION_DENIED"
  }
}

The same error occurs when using the API Explorer (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get).

At the same time, the document itself opens successfully from a link from any computer and from any browser even to unauthorized users.

This problem began on July 9 at 09:35 PM (UTC+0).

Prior to this error, I successfully received data from the document using the #1 key settings.

Update:

I found another strange nuance: on all other documents there is no such problem. An error is observed on one particular document. I compared the access settings with others - they are identical.

Update 2:

I tried to copy the table and open it via API - the error was the same. An hour later I tried again - it all worked.

Upvotes: 16

Views: 14386

Answers (3)

Ahmed I. Elsayed
Ahmed I. Elsayed

Reputation: 2130

API key is for getting public spread sheets, if you want to get private ones, consider using a service account

Upvotes: 0

Debu Shinobi
Debu Shinobi

Reputation: 2582

As @thinktwice said it is suggested to turn on the Anyone with the link option in the sheet.

I was using python and this created_spreadsheet.share('', role='reader', type='anyone') worked for me.

Upvotes: 0

thinktwice
thinktwice

Reputation: 151

After seeing HoverPhoenix comment, I change access of My sheet to ** Anyone with link** on Viewer mode.

Example Access Image

After changing the access it is working properly. If Data security is the concern then the best option is to use OAuth 2.0 Client IDs as credentials.

Upvotes: 3

Related Questions