如何通过 Google Apps 脚本管理 Google 联系人? (错误许可)

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

我已经尝试了所有我读过并且能想到的东西:

将范围添加到清单文件:

    {
      "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"
    }

在服务API中为人们提供支持

我删除了所有应用权限并从头开始

我试过更换浏览器,以防 cookie 成为可能

这就是我此时尝试联系的方式:

    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);
    }

这是我遇到的错误: 您无权调用 ContactsApp.getContactsByEmailAddress 所需权限:https://www.google.com/m8/feeds

我现在正在尝试读取联系人,并且会在我编辑包含现有联系人的行时更新它。

感谢您的帮助!

正如@Tanaike 所指出的,问题是由于目前 运行 是基于简单的触发器而不是可安装的触发器。谢谢!

参考:

Simple Triggers > Restrictions:

They cannot access services that require authorization.

Installable Triggers

Installable version can call services that require authorization. The installable version runs with the authorization of the user who created the trigger, even if another user with edit access opens the spreadsheet.