1
votes

I am trying to call the Google Sheets API via a Google Apps Script. As an example, I have followed the instructions provided here:

https://developers.google.com/sheets/api/quickstart/js

I have generated the client ID and API Key via my Google Cloud Platform project as suggested elsewhere.

Now, I have created a google apps script with two files, the Code.gs file and a file called index.html containing the code copied and pasted from the Google Sheets API Quickstart above (with my client ID and API inserted).

When testing deployment, I get the following error message:

{
  "error": "idpiframe_initialization_failed",
  "details": "Not a valid origin for the client: https://<some numbers>-script.googleusercontent.com has not been registered for client ID <MY_CLIENT_ID>. Please go to https://console.developers.google.com/ and register this origin for your project's client ID."
}

I have registered script.google.com as an origin for my project.

Am I doing something obviously wrong? How would I proceed from here to get past this error?

1
Welcome to Stack Overflow. Did you know that the Google Sheets API is already integrate in Google Apps Script? See the Advanced Services section in Apps Script docs.Rubén
Related to advanced services in Google Apps Script -> stackoverflow.com/q/65832570/1595451Rubén
@Rubén I wasn't aware of this. Thank you! Very helpful.vlfranz

1 Answers

1
votes

If you want to make use of the Sheets API in Apps Script you will have to make use of the Sheets Advanced Service.

For this you will have to go to Services + and then add the Google Sheets API:

sheets advanced service

Since this is an advanced service, the authorization flow will be handled by Google so you won't have to provide the clientId and the API key.

Reference