我尝试使用Google API for python删除日历的所有事件。 如果我一个一个地删除事件,这个工作正常,但它很长并且没有优化,所以我尝试使用ExecuteBatch做同样的事情,我用它在日历中插入很多条目(这在插入之前工作正常)。
def DeleteAllEntryOfCalendar(calendar_client, name_calendar):
#Request_feed for doing the delete
request_feed = gdata.calendar.CalendarEventFeed()
#Get the Uri of the cal we've to delete all entries
uri = GetUri(calendar_client, name_calendar)
feed = calendar_client.GetAllCalendarsFeed()
for a_cal in feed.entry:
if a_cal.title.text == name_calendar:
calendar = a_cal
#For each entry in the cal, do a delete request entry in request_feed
query = gdata.calendar.client.CalendarEventQuery()
query.max_results = 1000
feed = calendar_client.GetCalendarEventFeed(uri=uri, q=query)
for an_entry in feed.entry:
an_entry.batch_id = gdata.BatchId(text='delete-request')
request_feed.AddDelete(entry=an_entry)
entry = ''
# submit the batch request to the server
response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')
我收到了错误:
Traceback (most recent call last):
File "c.py", line 253, in <module>
DeleteAllEntryOfCalendar(client, name_calendar)
File "c.py", line 187, in DeleteAllEntryOfCalendar
response_feed = calendar_client.ExecuteBatch(request_feed, uri+u'/batch')
File "/usr/local/lib/python2.6/dist-packages/gdata/calendar/client.py", line 432, in execute_batch
return self.Post(batch_feed, url, desired_class=desired_class)
File "/usr/local/lib/python2.6/dist-packages/gdata/client.py", line 681, in post
entry.to_string(get_xml_version(self.api_version)),
AttributeError: 'CalendarEventFeed' object has no attribute 'to_string'
我重复一遍,当我这样做以插入事件时,这很好。 我经常搜索并尝试了很多可能性,但我无法做到这一点。 如果你有个主意......
答案 0 :(得分:1)
使用
gdata.calendar.data.CalendarEventFeed
gdata python库中的一些对象有两个版本,你不能将它们混合在一起。