Microsoft Graph API 是一个强大的工具,用于访问和管理 Microsoft 365 服务中的数据。要使用 Microsoft Graph API 按已分配计划过滤用户,你需要执行以下步骤:
User.Read.All
。以下是一个使用 Microsoft Graph SDK for Python 的示例代码,展示如何获取并过滤具有特定计划的用户:
from msgraphcore import GraphSession
from requests.auth import HTTPBasicAuth
# 配置客户端ID和密钥
client_id = 'your-client-id'
client_secret = 'your-client-secret'
tenant_id = 'your-tenant-id'
# 创建会话
session = GraphSession(client_id, client_secret, tenant_id, auth_provider=HTTPBasicAuth(client_id, client_secret))
# 构建查询URL,过滤具有Exchange基本功能的用户
query_url = "https://graph.microsoft.com/v1.0/users?$filter=assignedPlans/any(x:x/serviceName eq 'EXCHANGE_S_FOUNDATION' and x/capabilityStatus eq 'Enabled')"
# 发送请求
response = session.get(query_url)
# 处理响应
users = response.json().get('value', [])
for user in users:
print(user['displayName'])
通过以上步骤,你可以有效地使用 Microsoft Graph API 来过滤具有特定计划的用户。
领取专属 10元无门槛券
手把手带您无忧上云