python - Microsoft 365 Graph API - 如何读取所有用户的邮箱
问题描述
我有一个 Microsoft 365 管理员用户。我尝试使用 Microsoft 365 图形 API 阅读其他用户的电子邮件。
我根据Microsoft 教程从github采用了以下内容:
import requests
graph_endpoint = 'https://graph.microsoft.com/v1.0{0}'
def make_api_get_call(url, token, parameters=None):
headers = {
"Authorization": f'Bearer {token}',
"Accept": "application/json",
}
return requests.get(url, headers=headers, params=parameters, timeout=10)
def get_messages(access_token, user, results_to_return="10"):
get_messages_url = graph_endpoint.format(
f'/users/{user}/mailfolders/inbox/messages')
query_parameters = {
"$top": results_to_return,
"$select": "receivedDateTime,subject,from,body",
"$orderby": "receivedDateTime DESC",
}
return make_api_get_call(get_messages_url, access_token, parameters=query_parameters)
我能够阅读自己的电子邮件,但由于某种原因,当我尝试将变量用户设置为另一个电子邮件帐户时 - 我收到以下错误:
404: {"error":{"code":"ErrorItemNotFound","message":"在商店中找不到指定的对象。,进程未能获得正确的属性。","innerError":{"date ":"2021-09-13T04:33:48","request-id":"42bba137-a852-43e2-97e7-387a95892223","client-request-id":"42bba137-a852-43e2-97e7-387a95892223 "}}}
我需要做什么才能使其工作?谢谢。
解决方案
我有一个 Microsoft 365 管理员用户。我尝试使用 Microsoft 365 图形 API 阅读其他用户的电子邮件。
管理员用户没有读取其他人邮箱的权限,例如,如果您尝试在 OWA 或 Outlook 中执行此操作,您会遇到同样的问题。您需要使用 Add-MailboxPermission https://docs.microsoft.com/en-us/powershell/module/exchange/add-mailboxpermission?view=exchange-ps之类的东西明确委派对邮箱的访问
推荐阅读
- python - 将函数动态添加到数组列
- javascript - 解构会创建一个新变量吗?
- python - python web请求超时错误(requests.exceptions.ConnectTimeout:HTTPSConnectionPool)
- godot - Kinematicbody2D 接触 Area2D?
- c# - Xamarin Firebase RTDB 和权限被拒绝 401
- javascript - 我想从 firebase 中的所有用户那里获取帖子 react native
- javascript - 我有一个错误“ER_BAD_FIELD_ERROR”将数据发送到我的数据库
- mongodb - MongoDB 聚合错误(MongoError: BSONObj size: 20726581 (0x13C4335) 无效。)
- python - 我在尝试使用包含异常字符的 slug 字段时遇到错误消息
- css - CSS3 ::after 伪选择器不起作用