Search code examples
google-cloud-platformoauth-2.0

API has not been used in project before or it is disabled 403 error


I'm using App Scripts to connect to the Google's Content API. To authenticate via oAuth2 I'm setting the scopes in my appsscript.json file. I'm then calling ScriptApp.getOAuthToken() to get the necessary access token.

However, I'm getting a 403 response and the error as below:

Content API for Shopping has not been used in project XXXX before or it is disabled. 

Enable it by visiting https://console.developers.google.com/apis/api/shoppingcontent.googleapis.com/overview?project=XXXX then retry. 

If you enabled this API recently, wait a few minutes for the action to propagate to our 
systems and retry

The issue is that the project ID in the error does not match the ID of the project where my service account sits. In fact the project doesn't seem to exist at all.

I've enabled a client ID for the sheet's script ID and added it to the redirect URI section but it appears to be going to the wrong place. I am struggling to understand why I would be redirected to this non-existent project.

The appsscript.json is as follows:

{
  "timeZone": "Europe/London",
  "dependencies": {
    "libraries": [
      {
        "userSymbol": "OAuth2",
        "version": "41",
        "libraryId": "XXXX"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
      "https://www.googleapis.com/auth/content",
      "https://www.googleapis.com/auth/script.external_request"
    ]
}

Solution

  • Switch the script from a Default Cloud Platform project to your Standard Cloud Platform project

    • Here are the instructions how to change to the standard project - depending on either you use the new or legacy editor.

    • After switching successfully to the standard project - enable the Content API for Shopping and any other APIs you want to use in the GCP console.

    • In case you use a service account with impersonation, you also need to assign the service account the necessary scopes in the admin console as described here.