【发布时间】:2022-01-20 06:40:04
【问题描述】:
我正在尝试弄清楚如何访问我所属的不同 Outlook 组的日历。我正在使用 win32com 和 Python 3.9 来完成此任务,并且希望避免使用 RESTful/auth 令牌路线,因为这对于应该是插入一些日历约会的简单脚本来说是相当多的开销。
我可以使用以下代码自行预约:
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)
返回我个人日历中每个约会的主题行。
我也可以使用 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)
我读到您希望将创建所需日历的人的电子邮件/用户作为收件人传递,但我没有这样做。
在尝试使用创建者的电子邮件时,我收到以下错误:
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)
如果我尝试使用他们的 (lastName, firstName),我会得到以下信息:
pywintypes.com_error: (-2009857777, 'OLE error 0x8834010f', None, None)
请注意,我指的是 GROUP 日历,而不是共享日历。我不确定这两者之间是否真的有区别,但它们在 Outlook 中对我来说显示为不同的部分。
我一直在参考的一些参考资料(对于找到此页面并遇到此问题的其他人):
Read Outlook Events via Python
https://docs.microsoft.com/en-us/office/vba/api/outlook.namespace.getdefaultfolder(和相关页面)
Problem with read Outlook shared calendar via python
https://docs.microsoft.com/en-us/answers/questions/607061/how-to-create-new-events-share-calendar-with-pytho.html
【问题讨论】:
-
您在 Outlook 中看到共享日历吗?
-
@EugeneAstafiev 是的,如果我正常打开 Outlook,我可以看到组日历。
-
是公用文件夹吗?请参阅Create a Public Folder calendar in Exchange Online 了解更多信息。
-
@EugeneAstafiev 你必须被添加,它不是一个公共文件夹(除非我明白你所说的公共的意思)
标签: python outlook ms-office pywin32 win32com