要使用Graph API获取委托邮箱列表,你需要遵循以下步骤:
首先,你需要一个有效的访问令牌,以便与Microsoft Graph API进行交互。你可以使用OAuth 2.0客户端凭据授权流程来获取访问令牌。
一旦你有了访问令牌,你就可以调用Graph API来获取委托邮箱列表。以下是一个示例请求:
GET https://graph.microsoft.com/v1.0/me/delegateMailboxes
确保在请求头中包含你的访问令牌:
Authorization: Bearer <your_access_token>
如果你需要特定的查询参数,可以在请求体中指定。例如,你可以按名称筛选委托邮箱:
{
"filter": "displayName eq 'DelegateName'"
}
Graph API将返回一个JSON响应,其中包含委托邮箱的列表。以下是一个示例响应:
{
"value": [
{
"id": "delegateId1",
"displayName": "DelegateName1",
"emailAddress": {
"name": "DelegateName1",
"address": "delegate1@example.com"
}
},
{
"id": "delegateId2",
"displayName": "DelegateName2",
"emailAddress": {
"name": "DelegateName2",
"address": "delegate2@example.com"
}
}
]
}
以下是一个使用Python和requests
库的示例代码:
import requests
# 替换为你的访问令牌
access_token = 'your_access_token'
# Graph API端点
url = 'https://graph.microsoft.com/v1.0/me/delegateMailboxes'
# 请求头
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
# 发送请求
response = requests.get(url, headers=headers)
# 处理响应
if response.status_code == 200:
delegate_mailboxes = response.json().get('value', [])
for mailbox in delegate_mailboxes:
print(f"ID: {mailbox['id']}, Display Name: {mailbox['displayName']}, Email: {mailbox['emailAddress']['address']}")
else:
print(f"Error: {response.status_code} - {response.text}")
Mail.ReadWrite
或User.Read.All
权限是必需的。领取专属 10元无门槛券
手把手带您无忧上云