Admin SDK Enterprise 授權管理員服務

您可以使用 Admin SDK Enterprise License Manager 服務,在 Apps Script 中使用 Admin SDK Enterprise License Manager API。網域管理員可透過這個 API 指派、更新、擷取及刪除使用者授權。

參考資料

如要進一步瞭解這項服務,請參閱 Admin SDK Enterprise License Manager API 的參考說明文件。與 Apps Script 中的所有進階服務一樣,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);
  }
}