【发布时间】:2021-09-12 16:26:53
【问题描述】:
我编写了一个简单的 python 脚本来获取我公司租户中用户的收件箱。此特定用户的许可证是 Office F3。这是我的代码:
import O365
from O365 import Account, Connection, MSGraphProtocol, Message
scopes=['basic', 'message_all']
credentials=('user@domain', 'password')
account = Account(credentials = credentials)
if not account.is_authenticated: # will check if there is a token and has not expired
account.authenticate(scopes=scopes)
account.connection.refresh_token()
mailbox = account.mailbox()
inbox = mailbox.get_folder(folder_name='Inbox')
child_folders = inbox.get_folders(25)
for folder in child_folders:
print(folder.name, folder.parent_id)
for message in inbox.get_messages(5):
if message.subject == 'test':
print(message.body)
当我运行它时,它告诉我复制并粘贴一个 url,当我点击它时,我收到以下错误:
CMD prompt when I run the code
AADSTS700016:在目录“y”中找不到标识符为“x”的应用程序。如果租户管理员未安装应用程序或未获得租户中任何用户的同意,则可能会发生这种情况。您可能将身份验证请求发送给了错误的租户。
有人知道怎么解决吗?
【问题讨论】:
-
我从未使用过此 API,但故障排除步骤似乎很明显:该应用程序是由管理员安装还是由用户同意?您是否将身份验证请求发送给正确的租户?如果您已经检查过但没有找到解决方案,请edit 提供您尝试过的确切内容。
-
您是否尝试逐行调试代码?哪一行代码准确导致显示错误消息?
-
我没有收到代码错误。当我在我的 cmd 中运行它时,它会要求我粘贴一个认证 URL 并使用 cmd 提示符更新我的帖子