1

Here's the request URL format I am using currently:

postResURL = https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values/Reserved!B2:D7:append?valueInputOption=RAW&key=${API_KEY}

Here is my demo code:

const newRow = [[Date.now().toString(), '[email protected]', 'some u']];


 $.post({ 
    url: postResURL, contentType: 'application/json', data: JSON.stringify(newRow),
}).done(function(response) {
    if (response.updates) {
    console.log('Row added successfully:', response);
    } else {
    console.error('Error adding row:', response);
    alert('Error adding row.');
}

I kept on getting errors that looks like this:

{
"error": {
"code": 403,
"message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
"status": "PERMISSION_DENIED"
}
}

I checked my google sheet permissions, all the permissions allow for writing.

Interestingly, $.get() works to read values, so I am able to read values from a google sheet, therefore API keys and Client_ID must be correct. However, I don't know why I can't write values to the google sheet, I tried using different combinations of the request URL, I'm not sure if that's the issue or not.

6
  • 1
    From Here's the request URL format I am using currently: https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values/Reserved!B2:D7:append?valueInputOption=RAW&key=${API_KEY}, if you are trying to use "Method: spreadsheets.values.append" with the API key, unfortunately, in the current stage, the API key can be used to only GET method of Sheets API. So, please use it with the access token. But, if I misunderstood your script, I apologize.
    – Tanaike
    Commented Jul 8 at 11:50
  • 1
    The response suggests you are outside the authorization scope. Make sure your API Key is correct and that you have proper OAuth active for the session.
    – Twisty
    Commented Jul 8 at 14:39
  • @Tanaike I am currently using jquery post for the request using the API key. Maybe I need to switch to access tokens but I can't find information on the website. Can you provide more detail?
    – Ryan Wang
    Commented Jul 9 at 1:22
  • 1
    About your new question Maybe I need to switch to access tokens but I can't find information on the website. Can you provide more detail?, how about this official document? developers.google.com/identity/protocols/oauth2
    – Tanaike
    Commented Jul 9 at 1:24
  • @Tanaike I followed the steps and got client keys and Oauth and everything. However, the same error is still there. I think there is another error.
    – Ryan Wang
    Commented Jul 16 at 2:34

1 Answer 1

0
+50

I think Zerosheets would be preferable to you, rather than ironing out all the quirks of Google API.

Your sheet becomes an URL that you can GET or POST to. From what code you posted there'd be little to no change on how you access the data anyways.

Not the answer you're looking for? Browse other questions tagged or ask your own question.