0

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?

  • I've never used this API, but the troubleshooting steps seem obvious: Has the application been installed by an admin or consented to by a user? Did you send the authentication request to the right tenant? If you've already checked but haven't found a solution, please [edit] to include what you tried exactly. – wjandrea Jun 30 '21 at 15:30
  • Did you try to debug the code line-by-line? Which line of code exactly causes the error message to be shown? – Eugene Astafiev Jul 01 '21 at 21:09
  • I don't get an error on the code. When I run it in my cmd it asks me to paste an autentification URL ill update my post with the cmd prompt – Andres Espinel Jul 05 '21 at 14:26

1 Answers1

0

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.

hidebyte
  • 29
  • 4