1

我正在尝试获取校园谈话信息并插入 Google 日历。

我的问题是,我只能将事件插入默认日历(xxxx@gmail.com),但不能将事件插入其他日历(例如,名为“校园谈话”的日历)

我正在使用 python 来执行此操作,并且我正在使用 Google calendar api v2。

这是代码。

calendarExample 类在这里

email = raw_input("Email:")
password = raw_input("Password:")
infolist = CampusTalk("http://my.yingjiesheng.com/xuanjianghui_school_4.html")
calendar = calendarExample.CalendarExample(email,password)
# Delete old calendar
feed = calendar.cal_client.GetOwnCalendarsFeed()
for entry in feed.entry:
    if entry.title.text == "Campus Talk":
        print 'Deleting calendar: %s' % entry.title.text
        calendar.cal_client.Delete(entry.GetEditLink().href)
# Insert new calendar
calendar._InsertCalendar(title="Campus Talk",description="Calendar of Campus Talk",time_zone='Asia/Shanghai', hidden=False, location='Shanghai',color='#2952A3')

for campustalk_info in infolist:
    try:
        content = "%s\n%s\n%s\n%s\n%s"%(campustalk_info["city"],campustalk_info["school"],campustalk_info["location"],campustalk_info["time"].strftime("%Y-%m-%d %H:%M:%S"),campustalk_info["link"])
        if campustalk_info["time"] == "0":
            campustalk_info["time"] = campustalk_info["date"]
        start_time = (campustalk_info["time"]+datetime.timedelta(hours=-8)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
        end_time = (campustalk_info["time"]+datetime.timedelta(hours=-6)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
        calendar._InsertSingleEvent(title=campustalk_info["company"], content=content, where=campustalk_info["location"], start_time=start_time, end_time=end_time)
    except Exception,e:
        print e
print "Finished!"

如您所见,我创建了一个新日历“Campus Talk”,如何将事件插入此日历而不是默认日历?

请帮帮我,谢谢!

4

1 回答 1

0

_InsertCalendar返回一个Calendar对象(见第 1 行157)。calendar调用时使用该对象,而不是当前对象_InsertSingleEvent(如在 line 中557)。


例如注意对象的创建和使用talks

talks = calendar._InsertCalendar(title="Campus Talk", ... ,color='#2952A3')

....

talks._InsertSingleEvent(title=campustalk_info["company"], ... ,end_time=end_time)  

请注意,我已将长行缩写为...

于 2013-10-13T13:10:05.093 回答