简体   繁体   English

连接到微软图形 API

[英]Connect to microsoft graph API

I have created an azure application using the Microsoft azure platform.我使用Microsoft azure平台创建了一个azure应用程序。

using the below script I make an attempt to connect to the API using the credentials given when creating the azure application.使用以下脚本,我尝试使用创建azure应用程序时提供的凭据连接到 API。

from O365 import Account
credentials = ('azureApp_clientId', 'azureApp_clientSecret')

account = Account(credentials)
if account.authenticate(scopes=['Mail.Read']):
   print('Authenticated!')

When the script runs it returns a URL to add to a browser and give consent..当脚本运行时,它会返回一个 URL 以添加到浏览器并表示同意。

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?xxxxxxxxxx

When i paste the URL into my browser it does nothing and returns a blank page..当我将 URL 粘贴到我的浏览器时,它什么都不做并返回一个空白页面。

This is my redirect URI in the azure app这是我在azure应用程序中的重定向 URI 在此处输入图片说明

What am I missing??我错过了什么??

Docs to o365 Lib here https://pypi.org/project/O365/ o365 Lib 文档https://pypi.org/project/O365/

Update更新

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)

Update更新

在此处输入图片说明

According to the configuration of the application azure (you register the application as Mobile and desktop applications), you should use the method Authenticate on behalf of a user (public) to do auth and should not provide client_secret.根据应用程序azure的配置(您将应用程序注册为移动和桌面应用程序),您应该使用Authenticate on behalf of a user (public)进行Authenticate on behalf of a user (public)的方法进行Authenticate on behalf of a user (public)并且不应提供client_secret. For more details, please refer to here and here .有关详细信息,请参阅此处此处

For example例如

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)

在此处输入图片说明


#Update My configuration #更新我的配置在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM