I have successfully been able to access my own calendar events by registering an app in Azure and calling the Microsoft Graph API via o365. Here is the code I've been using, thanks to an article I found online:
from O365 import Account, MSGraphProtocol
#gets us access to the API
CLIENT_ID = 'my client id'
SECRET_ID = 'my secret id'
credentials = (CLIENT_ID, SECRET_ID)
protocol = MSGraphProtocol()
scopes = ['https://graph.microsoft.com/.default']
account = Account(credentials, protocol=protocol)
if account.authenticate(scopes=scopes):
print('Authenticated!')
#calls calendar event
schedule = account.schedule()
calendar = schedule.get_default_calendar()
From here, I am able to access the events from my own calendar.
But ultimately, I need to be able to access the events from a shared calendar.
Based on the documentation I found for o365, I tried changing the "resource" to the email of the shared calendar I would like to access. My code looks like this:
schedule2 = account.schedule(resource = 'name@gmail.com')
calendar2 = schedule2.get_default_calendar()
Then, I get this error once I call the get_default_calendar() (i.e. defining calendar2) function:
Client Error: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/users/name@gmail.com/calendar | Error Message: The requested user 'name@gmail.com' is invalid.
...
raise HTTPError('{} | Error Message: {}'.format(e.args[0], error_message), response=response) from None
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/users/name@gmail.com/calendar | Error Message: The requested user 'name@gmail.com' is invalid.
Now, the email definitely exists and has its own outlook account. Also, my API permissions include Calendars.Read.Shared. I'm guessing the issue is that this is not the proper way to get the shared calendar, but relentless googling hasn't shown me another way. I've also looked at this article and I don't understand how to use this information in the context of o365.
Is the issue within the resource I plugged in? Or is there an alternative way to access a shared calendar? I am a beginner python user so any insight is appreciated. I feel like this is a rather simple task but I am just missing the correct function. Thanks!