首页 > 解决方案 > 我正在尝试使用 python 脚本从 Outlook 中获取日历。我收到无效的范围值错误。我错过了什么?

问题描述

我正在尝试使用 Python 脚本在 Outlook 中获取我的共享日历。我是一年级计算机科学专业和初学者。我认为将我所有的日历事件都打印到终端会很好,我认为这个小活动会让我受益。但是,在将登录门户链接粘贴到 chrome 后,我的浏览器中出现无效范围值错误。我已将我认为需要的所有权限和平台配置添加到 Azure?我错过了什么?

浏览器错误:

https://login.microsoftonline.com/common/oauth2/nativeclient?error=invalid_scope&error_description=The%20provided%20value%20for%20the%20input%20parameter%20%27scope%27%20is%20not%20valid.%20The%20scope%20%27Calendars.Read.Shared%27%20is%20not%20valid.&state=iC6gDfcX1C7BCPfsrvdHpp4a7kzcRr

终端输出:

Visit the following url to give consent:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id=844ecf49-96c1-422d-a611-b7bad4882745&redirect_uri=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fnativeclient&scope=Calendars.Read.Shared&state=iC6gDfcX1C7BCPfsrvdHpp4a7kzcRr&access_type=offline
Paste the authenticated url here:

这是我的代码:

from O365 import Account, MSGraphProtocol

CLIENT_ID = '844ecf49-96c1-422d-a611-b7bad4882745'
SECRET_ID = 'q~-n~w9_kTb6mTIrbmcA2-139rqiSph4n_'
SCOPE = ["Calendars.Read.Shared"]

credentials = (CLIENT_ID, SECRET_ID)

protocol = MSGraphProtocol()

account = Account(credentials, protocol=protocol)

if account.authenticate(scopes=SCOPE):
    print("Authenticated!")

schedule = account.schedule()
calendar = schedule.get_default_calendar()
events = calendar.get_events(include_recurring=False)

for event in events:
    print(event)

Azure 映像中的权限

Azure 中的平台配置

标签: pythonauthenticationoutlook

解决方案


推荐阅读