Well, I would like to get a calendars data from outlook. My purpose is making small service in Python which can read & write in someones calendar in outlook account of course I suppose that I was provided access to it in Azure Active Directory. Before writing this, I read a lot of guides on how to do this. Also I tried to find similar issues on
from O365 import Account
CLIENT_ID = 'xxxx'
SECRET_ID = 'xxxx'
TENANT_ID = 'xxxx'
credentials = (CLIENT_ID, SECRET_ID)
account = Account(credentials, auth_flow_type='credentials', tenant_id=TENANT_ID)
if account.authenticate():
print('Authenticated!')
schedule = account.schedule(resource='user@domain')
calendar = schedule.get_default_calendar()
events = calendar.get_events(include_recurring=False)
for event in events:
print(event)
Then if I use email which is shown in user contact info in my directory as a resourse. I get this error:
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/users/user@domain/calendar | Error Message: The tenant for tenant guid 'xxxx' does not exist.
Then if I use 'User Principal Name', which is shown in user identity in my directory as a resourse. I get this error:
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/users/xxxx#EXT#@xxxx.onmicrosoft.com/calendar | Error Message: Insufficient privileges to complete the operation.
Then if I use 'me' as a resource I also get an error:
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/me/calendar | Error Message: /me request is only valid with delegated authentication flow.
Could you tell me what should i provide as a resource to get someones calendar or maybe what should i fix?
CodePudding user response:
For me, joining Microsoft Developer Program and using its azure directory fixed issues.