Admin SDK Enterprise License Manager 服务

借助 Admin SDK Enterprise License Manager 服务,您可以在 Apps 脚本中使用 Admin SDK Enterprise License Manager API。借助此 API,网域管理员可以分配、更新、检索和删除用户许可。

参考

如需详细了解此服务,请参阅 Admin SDK Enterprise License Manager API 的参考文档。与 Apps 脚本中的所有高级服务一样,Admin SDK Enterprise License Manager 服务使用的对象、方法和参数与公共 API 相同。如需了解详情,请参阅如何确定方法签名

如需报告问题和寻求其他支持,请参阅 Admin SDK Enterprise License Manager 支持指南

示例代码

以下示例代码使用的是该 API 的版本 1

获取域名的许可分配列表

此示例记录网域中用户的许可分配,包括产品 ID 和 SKU ID。请注意使用页面令牌来访问完整的结果列表。

advanced/adminSDK.gs
/**
 * Logs the license assignments, including the product ID and the sku ID, for
 * the users in the domain. Notice the use of page tokens to access the full
 * list of results.
 */
function getLicenseAssignments() {
  const productId = 'Google-Apps';
  const customerId = 'example.com';
  let assignments = [];
  let pageToken = null;
  do {
    const response = AdminLicenseManager.LicenseAssignments.listForProduct(productId, customerId, {
      maxResults: 500,
      pageToken: pageToken
    });
    assignments = assignments.concat(response.items);
    pageToken = response.nextPageToken;
  } while (pageToken);
  // Print the productId and skuId
  for (const assignment of assignments) {
    console.log('userId: %s, productId: %s, skuId: %s',
        assignment.userId, assignment.productId, assignment.skuId);
  }
}

插入用户的许可分配

此示例演示了如何针对指定的产品 ID 和 SKU ID 组合插入用户的许可分配。

advanced/adminSDK.gs
/**
 * Insert a license assignment for a user, for a given product ID and sku ID
 * combination.
 * For more details follow the link
 * https://developers.google.com/admin-sdk/licensing/reference/rest/v1/licenseAssignments/insert
 */
function insertLicenseAssignment() {
  const productId = 'Google-Apps';
  const skuId = 'Google-Vault';
  const userId = 'marty@hoverboard.net';
  try {
    const results = AdminLicenseManager.LicenseAssignments
        .insert({userId: userId}, productId, skuId);
    console.log(results);
  } catch (e) {
    // TODO (developer) - Handle exception.
    console.log('Failed with an error %s ', e.message);
  }
}