使用pyexchange访问共享日历

时间:2016-07-20 14:43:10

标签: python outlook pyexchange

我试图访问和阅读“#Calendars"基于pyexchange和以下代码:

from pyexchange import Exchange2010Service, ExchangeNTLMAuthConnection
from datetime import datetime
from pytz import timezone

#Connection
URL = 'https://<server name>/EWS/Exchange.asmx'
USERNAME = '<Domain>\\<User Name>'
PASSWORD = '<Your Password>'

# Set up the connection to Exchange
connection = ExchangeNTLMAuthConnection(url=URL,
                                        username=USERNAME,
                                        password=PASSWORD)

service = Exchange2010Service(connection)

# List all events from date to date
calendar_list = service.calendar().list_events(
    start=timezone('Europe/Amsterdam').localize(datetime(2016, 6, 1)),
    end=timezone('Europe/Amsterdam').localize(datetime(2016, 6, 30)),
    details=True
)

for event in calendar_list.events:
    print("{start} ------ {stop} ------ {subject}".format(
        start=event.start,
        stop=event.end,
        subject=event.subject
    ))

我的日历一切都很好,但我不知道如何为3&#34;共享日历&#34;做同样的事情: Screenshot of my calendar view

知道如何列出3&#34;共享日历&#34;?我在Mac上使用Outlook。

1 个答案:

答案 0 :(得分:2)

我可以解决同样的问题。

 connection = ExchangeNTLMAuthConnection(url=URL,
                                    username=USERNAME,
                                    password=PASSWORD)
 service = Exchange2010Service(connection)
 my_calendar = service.calendar()
 events = my_calendar.list_events(
     start=timezone("US/Eastern").localize(datetime(2014, 10, 1, 11, 0, 0)),
     end=timezone("US/Eastern").localize(datetime(2014, 10, 29, 11, 0, 0)),
     details=True,
     delegate_for=u'his_email_address@abc.com' ### This is the key point!!
 )
 for event in events.events:
     print "{start} {stop} - {subject}".format(
         start=event.start,
         stop=event.end,
         subject=event.subject
     )

您可以使用&#34; delegate_for&#34;选项。您可能需要使用pyexchange 0.7-dev。

在下方运行以安装它。

sudo pip install git+https://github.com/linkedin/pyexchange.git