Admin SDK Enterprise License Manager 服务

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

参考

如需详细了解此服务,请参阅 Admin SDK 企业版许可管理器 API 的参考文档。与 Apps 脚本中的所有高级服务一样,Admin SDK 企业许可管理器服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的

如需报告问题并寻求其他支持,请参阅 Admin SDK 企业版许可管理器支持指南

示例代码

以下示例代码使用 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);
  }
}