Search code examples
jsongoogle-apps-scriptidegoogle-oauthmanifest

Won't allow me to save edits to appsscript.json


I'd like to access the name associated with a users google account to resolve a GoogleJsonResponseException: API call to people.people.get failed with error: The caller does not have permission to request "people/me". Request requires one of the following scopes: [profile] error.

To do that, I'm attempting to include the https://www.googleapis.com/auth/userinfo.profile scope as listed on Google's list of OAuth 2.0 scopes. However, after editing the appsscript.json to manually include the scope, as outlined here, and attempting to save, it does not work. It displays the "Saving project..." popup, but it never resolves and reloading the page resets appsscript.json without my changes. The scope https://www.googleapis.com/auth/userinfo has the same response. There is no error message associated with this.

Here is my current file- have I missed something silly? Am I going about it wrong?

{
  "oauthScopes": "https://www.googleapis.com/auth/userinfo.names",
  "timeZone": "America/New_York",
  "dependencies": {
    "enabledAdvancedServices": [
      {
        "userSymbol": "People",
        "version": "v1",
        "serviceId": "peopleapi"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "webapp": {
    "executeAs": "USER_DEPLOYING",
    "access": "MYSELF"
  }
}

Solution

  • The Google Apps Script IDE / online Editor doesn't allow to save the project if any of the files have a syntax error. In the specific case of Apps Script project manifest (appsscript.json) this file should have a valid JSON and should have a specific structure.

    The Apps Script project manifest structure is specified in https://developers.google.com/apps-script/manifest.


    In the specific case mentioned by the OP, the oauthScopes property should contain an Array or strings. Considering this, change

    "oauthScopes": "https://www.googleapis.com/auth/userinfo.names",
    

    by

    "oauthScopes": [ "https://www.googleapis.com/auth/userinfo.names" ],
    

    Another typical error when manually editing the manifest is to forget to add a comma to separate two properties.