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。
请注意,您可以使用页面令牌来访问完整的结果列表。
为用户插入许可分配
此示例演示了如何针对给定的产品 ID 和 SKU ID 组合为用户插入许可分配。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Admin SDK Enterprise License Manager service enables domain admins to manage user licenses within Apps Script using the Admin SDK Enterprise License Manager API.\u003c/p\u003e\n"],["\u003cp\u003eIt allows for assigning, updating, retrieving, and deleting user licenses for various products.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service that requires enabling before use and utilizes the same structure as the public API.\u003c/p\u003e\n"],["\u003cp\u003eProvided sample code demonstrates how to retrieve and assign licenses using the API.\u003c/p\u003e\n"]]],[],null,["# Admin SDK Enterprise License Manager Service\n\nThe Admin SDK Enterprise License Manager service allows you to use the\n[Admin SDK Enterprise License Manager API](/admin-sdk/licensing) in\nApps Script. This API allows domain admins to assign, update, retrieve, and\ndelete user licenses.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/admin-sdk/licensing/v1/reference) for the\nAdmin SDK Enterprise License Manager API. Like all advanced services in Apps\nScript, the Admin SDK Enterprise License Manager service uses the same objects,\nmethods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Admin SDK Enterprise License Manager support guide](/admin-sdk/licensing/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/admin-sdk/groups-migration/v1/reference)\nof the API.\n\n### Get a list of license assignments for the domain\n\nThis sample logs the license assignments, including the product ID and the\nsku ID, for the users in the domain.\nNotice the use of page tokens to access the full list of results. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Logs the license assignments, including the product ID and the sku ID, for\n * the users in the domain. Notice the use of page tokens to access the full\n * list of results.\n */\nfunction getLicenseAssignments() {\n const productId = 'Google-Apps';\n const customerId = 'example.com';\n let assignments = [];\n let pageToken = null;\n do {\n const response = AdminLicenseManager.LicenseAssignments.listForProduct(productId, customerId, {\n maxResults: 500,\n pageToken: pageToken\n });\n assignments = assignments.concat(response.items);\n pageToken = response.nextPageToken;\n } while (pageToken);\n // Print the productId and skuId\n for (const assignment of assignments) {\n console.log('userId: %s, productId: %s, skuId: %s',\n assignment.userId, assignment.productId, assignment.skuId);\n }\n}\n```\n\n### Insert a license assignment for a user\n\nThis sample demonstrates how to insert a license assignment for a user, for a\ngiven product ID and sku ID combination. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Insert a license assignment for a user, for a given product ID and sku ID\n * combination.\n * For more details follow the link\n * https://developers.google.com/admin-sdk/licensing/reference/rest/v1/licenseAssignments/insert\n */\nfunction insertLicenseAssignment() {\n const productId = 'Google-Apps';\n const skuId = 'Google-Vault';\n const userId = 'marty@hoverboard.net';\n try {\n const results = AdminLicenseManager.LicenseAssignments\n .insert({userId: userId}, productId, skuId);\n console.log(results);\n } catch (e) {\n // TODO (developer) - Handle exception.\n console.log('Failed with an error %s ', e.message);\n }\n}\n```"]]