我尝试使用 Google API for python 删除日历的所有事件。如果我一一删除事件,这可以正常工作,但它很长并且不是未优化的,因此我尝试使用 ExecuteBatch 执行相同的操作,该 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'
我重复一遍,当我做同样的事情来插入事件时,它工作得很好。我进行了很多搜索并尝试了很多可能性,但我无法做到。如果你有一个想法...