I coded a simple python script to get the inbox of an user in my company's tenant. The licence in this specific user is an Office F3. Here is my code:
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)
When I run it it tells me to copy and paste an url and when i click on it i get the following error:
CMD prompt when I run the code
AADSTS700016: Application with identifier 'x' was not found in the directory 'y'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
Anyone knows how to fix it?
The answer comes a few months late, but if someone has the same problem, the person is happy to find the answer here.
Your error message is the default login link for o365 via the Graph API. (The URL is wrong (%2F = /), probably due to an outdated version of the Jupyter Notebook?)
To stay logged in, I recommend specifying as scope: 'offline_access'. This will create a token that allows authentication without a login link.