[英]Connect to microsoft graph API
我使用Microsoft azure
平台创建了一个azure
应用程序。
使用以下脚本,我尝试使用创建azure
应用程序时提供的凭据连接到 API。
from O365 import Account
credentials = ('azureApp_clientId', 'azureApp_clientSecret')
account = Account(credentials)
if account.authenticate(scopes=['Mail.Read']):
print('Authenticated!')
当脚本运行时,它会返回一个 URL 以添加到浏览器并表示同意。
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?xxxxxxxxxx
当我将 URL 粘贴到我的浏览器时,它什么都不做并返回一个空白页面。
我错过了什么??
o365 Lib 文档https://pypi.org/project/O365/
更新
from O365 import Account
credentials = ('myclientID')
account = Account(credentials, auth_flow_type = 'public')
if account.authenticate(scopes = ['Mail.Read']):
print('Authenticated!')
mailbox = account.mailbox()
inbox = mailbox.inbox_folder()
for message in inbox.get_messages():
print(message)
更新
根据应用程序azure
的配置(您将应用程序注册为移动和桌面应用程序),您应该使用Authenticate on behalf of a user (public)
进行Authenticate on behalf of a user (public)
的方法进行Authenticate on behalf of a user (public)
并且不应提供client_secret.
有关详细信息,请参阅此处和此处。
例如
from O365 import Account
credentials = ('<your client_id>',)
account = Account(credentials,auth_flow_type='public')
if account.authenticate(scopes==['Mail.Read'] ):
print('Authenticated!')
mailbox = account.mailbox()
inbox = mailbox.inbox_folder()
for message in inbox.get_messages():
print(message)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.