【发布时间】:2018-02-25 19:17:21
【问题描述】:
我的用例是:制作一个每小时运行一次的脚本,以提取有关用户日历的信息。
我的脚本在 Python 中运行,我得到了一个令牌,但我无法获取用户的事件。我已经在Microsoft Application Registration Portal 中注册了我的应用程序并授予了 Calendar.read 应用程序权限。管理员通过访问/adminconsent 端点表示同意。
这是我获取令牌的代码(文档here):
url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
data = {
'grant_type': 'client_credentials',
'client_id': app_id,
'scope': 'https://graph.microsoft.com/.default', <--- Really not sure about this here
'client_secret': client_secret,
}
r = requests.post(url, data=data)
token = r.json().get('access_token')
我应该使用什么范围?文档只提到了上面的那个。
并读取用户的日历:
url = 'https://outlook.office.com/api/v2.0/users/{}/events'.format(user_email)
headers = {
'Authorization': 'Bearer {}'.format(token)
}
r = requests.get(url, headers=headers)
我不确定users/{user_email}/ 部分。
我获得了访问令牌,但在尝试读取用户的日历时出现以下错误:
响应 [401]
访问令牌是使用一种太弱的身份验证方法获取的,该方法不允许此应用程序访问。提交的身份验证强度为 1,要求为 2。
【问题讨论】:
标签: python oauth-2.0 office365api outlook-restapi