I'm trying to figure out how I can access the calendars for different Outlook groups that I am apart of. I'm using win32com and Python 3.9 for this task, and would prefer to avoid going the RESTful/auth token route as that would be a fair bit of overhead for what is supposed to be a simple script inserting a few calendar appointments.
I'm able to get my own appointments using the following code:
import win32com.client
application = win32com.client.Dispatch('Outlook.Application')
namespace = application.GetNamespace('MAPI')
cal = namespace.GetDefaultFolder(9)
for item in cal.Items:
print(item.Subject)
Returning the subject line of every appointment in my personal calendar.
I'm also able to get the same information using GetSharedDefaultFolder:
application = win32com.client.Dispatch('Outlook.Application')
namespace = application.GetNamespace('MAPI')
recipient = namespace.createRecipient("{my_email}")
resolved = recipient.Resolve()
sharedCalendar = namespace.GetSharedDefaultFolder(recipient, 9)
for item in sharedCalendar.Items:
print(item.Subject)
I read that you want to pass the email/user of the person who created the desired calendar as the recipient, but I have had no luck with this.
In attempting to use the creator's email, I get the following error:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The operation failed because of a registry or installation problem. Restart Outlook and try again. If the problem persists, reinstall.', None, 0, -2147221219), None)
And if I attempt to use their (lastName, firstName), I get the following:
pywintypes.com_error: (-2009857777, 'OLE error 0x8834010f', None, None)
Note that I'm referring to GROUP calendars, not Shared Calendars. I'm not sure if there's actually a difference between the two, but they appear as different sections on Outlook for me.
Some references I've been referring to (for others who find this page and are having this issue):
Read Outlook Events via Python
https://learn.microsoft.com/en-us/office/vba/api/outlook.namespace.getdefaultfolder (and related pages)
Problem with read Outlook shared calendar via python
https://learn.microsoft.com/en-us/answers/questions/607061/how-to-create-new-events-share-calendar-with-pytho.html