为什么我不能在 python 中使用 O365 包?

发布于 2025-01-19 09:19:36 字数 1600 浏览 2 评论 0原文

以下是我用来与 Office 365 交互的代码:

from O365 import Account
credentials = ('...', '...')
account = Account(credentials)
if account.authenticate(scopes=['basic', 'message_all']):
   print('Authenticated!')

运行 python 文件后,我得到一个 URL,然后单击该 URL:

AADSTS50194:应用程序“...”(测试)未配置为多用途租户申请。对于“2018 年 10 月 15 日”之后创建的此类应用程序,不支持使用 /common 端点。使用特定于租户的端点或将应用程序配置为多租户。

我设置“仅限此组织目录中的帐户”,因为我只希望公司中的人员可以访问该应用程序。

我还设置了这个(如你所见,我设置了重定向 URL ): 输入图片这里的描述

我在这里遗漏了什么吗?

这是我的新代码:

from O365 import Account

credentials = ('..', '..')

# the default protocol will be Microsoft Graph

account = Account(credentials, auth_flow_type='credentials', tenant_id='..')
if account.authenticate():
   print('Authenticated!')

storage = account.storage()
print(storage)
my_drive = storage.get_default_drive()  # or get_drive('drive-id')
print(my_drive)
root_folder = my_drive.get_root_folder()
attachments_folder = my_drive.get_special_folder('attachments')

它可以获得“已验证!”,但我收到以下错误:

Client Error: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/drive/root | Error Message: Either scp or roles claim need to be present in the token.

{"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError":{"date":"2022-04-07T01:24:20","request-id":"be71cdcf-6f69-4d6f-b344-588d0b693253","client-request-id":"be71cdcf-6f69-4d6f-b344-588d0b693253"}}}

谢谢

Here is the code that I am using to interactive with Office 365:

from O365 import Account
credentials = ('...', '...')
account = Account(credentials)
if account.authenticate(scopes=['basic', 'message_all']):
   print('Authenticated!')

After I run the python file, I get a URL, and I click the URL:

AADSTS50194: Application '...'(test) is not configured as a multi-tenant application. Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant.

I set "Accounts in this organizational directory only" because I only want the people in my company can access the app.

I also set this (as you can see, I have set the redirect URL ):
enter image description here

Am I missing something here?

Here is my new code:

from O365 import Account

credentials = ('..', '..')

# the default protocol will be Microsoft Graph

account = Account(credentials, auth_flow_type='credentials', tenant_id='..')
if account.authenticate():
   print('Authenticated!')

storage = account.storage()
print(storage)
my_drive = storage.get_default_drive()  # or get_drive('drive-id')
print(my_drive)
root_folder = my_drive.get_root_folder()
attachments_folder = my_drive.get_special_folder('attachments')

It can get "Authenticated!", but I get the following error:

Client Error: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/drive/root | Error Message: Either scp or roles claim need to be present in the token.

{"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError":{"date":"2022-04-07T01:24:20","request-id":"be71cdcf-6f69-4d6f-b344-588d0b693253","client-request-id":"be71cdcf-6f69-4d6f-b344-588d0b693253"}}}

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街九尾狐 2025-01-26 09:19:36

您需要找到您的租户 ID(它将在应用程序注册中列出)

在此处输入图像描述

然后将其传递到例如

from O365 import Account

credentials = ('my_client_id', 'my_client_secret')

# the default protocol will be Microsoft Graph

account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id')
if account.authenticate():
   print('Authenticated!')

You need to find your tenant Id (it will be listed on the application registration)

enter image description here

and then pass that in eg

from O365 import Account

credentials = ('my_client_id', 'my_client_secret')

# the default protocol will be Microsoft Graph

account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id')
if account.authenticate():
   print('Authenticated!')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文