Apps 脚本插件:如何跟踪管理域安装?

Apps Script Addon: How to track admin domain install?

我正在尝试获取安装我的插件的用户的电子邮件列表。

我正在使用 onInstall 触发器获取电子邮件并将其推送到我的数据库。

单独安装(普通 gmail 或什至选择单独安装的管理员)就可以了

但是 Domain InstallonInstall 事件没有触发

那么如何跟踪域安装?

我们可以使用 G Suite Marketplace 的 LicenseNotification 端点 API:

https://developers.google.com/gsuite/marketplace/v2/reference/licenseNotification/list

结果将是这样的:

{
  "kind": "appsmarket#licenseNotificationList",
  "notifications": [
    {
      "kind": "appsmarket#licenseNotification",
      "id": "001566972002228000-000001",
      "applicationId": "xxx",
      "customerId": "test@gmail.com",
      "timestamp": "1566972001590",
      "provisions": [
        {
          "kind": "appsmarket#provisionNotification",
          "editionId": "default_edition",
          "seatCount": "1"
        }
      ]
    },
    {
      "kind": "appsmarket#licenseNotification",
      "id": "001568364120883000-000001",
      "applicationId": "xxx",
      "customerId": "domainabc.com",
      "timestamp": "1568364119585",
      "provisions": [
        {
          "kind": "appsmarket#provisionNotification",
          "editionId": "default_edition",
          "seatCount": "-1"
        }
      ]
    },
    ...
  ],
  "nextPageToken": "001569976724468000-000001"
}

notifications 数组中,注意一些具有 "seatCount": "-1"

的对象

这些是我们正在寻找的域安装。

我们只需要获取里面的值"customerId": "domainabc.com",