【发布时间】:2018-03-27 21:18:58
【问题描述】:
我正在按照Get access without a user 指南编写一个调用 Microsoft Graph 的 Python 脚本。
此脚本将从 cron 安排,因此无法获得管理员同意(因此授权使用客户端凭据)。我可以使用此调用成功获取令牌:
request_url = "https://login.microsoftonline.com/mytenant.onmicrosoft.com/oauth2/v2.0/token"
data = {
'Host' : 'login.microsoftonline.com',
'Content-Type' : 'application/x-www-form-urlencoded',
'client_id' : 'my-client-id-1234',
'scope' : 'https://graph.microsoft.com/.default',
'client_secret' : client_secret,
'grant_type' : 'client_credentials'
}
response = requests.post(url = request_url, data = data)
然后我尝试使用有效令牌通过此调用获取用户列表:
request_url = "https://graph.microsoft.com/v1.0/users"
headers = {
'Authorization' : 'Bearer ' + token,
'Host' : 'graph.microsoft.com'
}
response = requests.get(url = request_url, headers = headers)
问题是我收到Authorization_IdentityNotFound 错误:
<Response [401]>
{
"error": {
"code": "Authorization_IdentityNotFound",
"message": "The identity of the calling application could not be established.",
"innerError": {
"request-id": "2257f532-abc4-4465-b19f-f33541787e76",
"date": "2018-03-27T19:11:07"
}
}
}
这些是我选择的权限:
知道如何解决这个错误吗?
【问题讨论】:
标签: python microsoft-graph-api