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 支援指南

程式碼範例

下方程式碼範例使用第 1 版的 API。

取得網域的授權指派清單

這個範例為網域中的使用者記錄授權指派作業,包括產品 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);
  }
}