为什么我不能在 python 中使用 O365 包?
以下是我用来与 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 端点。使用特定于租户的端点或将应用程序配置为多租户。
我设置“仅限此组织目录中的帐户”,因为我只希望公司中的人员可以访问该应用程序。
我在这里遗漏了什么吗?
这是我的新代码:
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 ):
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要找到您的租户 ID(它将在应用程序注册中列出)
然后将其传递到例如
You need to find your tenant Id (it will be listed on the application registration)
and then pass that in eg