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);
  }
}