google-apps-scriptgoogle-sheetsgoogle-contacts-api

How to manage Google Contacts via Google Apps Script? (errors with permission)


I have tried all sorts of things I have read and can think of:

Added the scope to the manifest file:

    {
      "timeZone": "America/Fortaleza",
      "dependencies": {
        "enabledAdvancedServices": [
          {
            "userSymbol": "People",
            "version": "v1",
            "serviceId": "peopleapi"
          }
        ]
      },
      "oauthScopes": [
        "https://www.google.com/m8/feeds",
        "https://www.googleapis.com/auth/spreadsheets"
      ],
      "exceptionLogging": "STACKDRIVER",
      "runtimeVersion": "V8"
    }

Enabled the People API in Services

I've deleted all apps permissions and started from scratch

I've tried changing the browser, in case cookies were a possibility

This is how I'm at this point trying to get a contact:

    function onEdit(e) {
        var sht = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Contacts"); 
        var rng = e.range;
        var row = rng.getRow();
        var drng = sht.getRange(row, 2, 1, 22).getValues();
        var email = sht.getRange(row, 2, 1, 1).getValue();
    
        var gmailContact = ContactsApp.getContactsByEmailAddress(email);
        Logger.log(gmailContact);
    }

This is the error I'm getting: You do not have the permission to call ContactsApp.getContactsByEmailAddress Required permissions: https://www.google.com/m8/feeds

I'm trying to read contacts now and will get it updated as I edit a row containing an existing contact.

Appreciate your help!


Solution

  • As pointed out by @Tanaike, the issues is due to the fact that this currently running on a simple trigger basis and not on an installable one. Thank you!

    Reference:

    Simple Triggers > Restrictions:

    They cannot access services that require authorization.