gpt4 book ai didi

azure - MS图API : invalid authentication token

转载 作者:行者123 更新时间:2023-12-04 05:02:20 25 4
gpt4 key购买 nike

我正在尝试使用 Microsoft Graph API 查询 Outlook/O365 邮箱中的邮件。我registered my app在 Azure 门户中,并收到查询 API 所需的信息。该应用具有 Mail.Read 权限。 (我无权访问 Azure 门户,有人告诉我它是这样设置的。)但是,当我从 OAuth 端点获取 token 时,它在任何后续调用中都不起作用。我现在正在使用 Python 的 requests 模块进行测试。

为什么此调用失败?看起来我传递了所有正确的信息,但我显然遗漏了一些东西。

我通过执行 POST 来获取 token :

https://login.microsoftonline.com/my.domain/oauth2/token

我传递必要的参数:

data = {'grant_type': 'client_credentials', 'client_id': CLIENTID, 'client_secret': SECRET, 'resource': APPURI}

我得到这样的回复:

{
'resource': 'APPURI',
'expires_in': '3599',
'ext_expires_in': '3600',
'access_token': 'TOKENHERE',
'expires_on': '1466179206',
'not_before': '1466175306',
'token_type': 'Bearer'
}

但是,我尝试使用该 token ,但它对我调用的任何内容都不起作用。我将其作为标题传递:

h = {'Authorization': 'Bearer ' + TOKEN}

我正在调用此网址:

url = 'https://graph.microsoft.com/v1.0/users/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e5889ccb8088848c89cb84818197809696a5809d8488958980cb868a88" rel="noreferrer noopener nofollow">[email protected]</a>/messages'

具体来说,我用这个:

r = requests.get(url, headers=h)

响应是 401:

{
'error': {
'innerError': {
'date': '2016-06-17T15:06:30',
'request-id': '[I assume this should be removed for privacy]'
},
'code': 'InvalidAuthenticationToken',
'message': 'Access token validation failure.'
}
}

最佳答案

在您的登录请求中,资源参数应为 https://graph.microsoft.com

关于azure - MS图API : invalid authentication token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37885476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com