开发者

Google Cal API Python : Multiple delete with ExecuteBatch failure

开发者 https://www.devze.com 2023-04-11 12:00 出处:网络
I try to delete all the events of a calendar using the Google API for python. If I delete the events one by one this works fine but it\'s very long and not unoptimized so I try to do the same thing us

I try to delete all the events of a calendar using the Google API for python. If I delete the events one by one this works fine but it's very long and not unoptimized so I try to do the same thing using ExecuteBatch that I use for insert a lot of entries in the calendar (and this works fine before the insert).

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')

And I got the error :

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'

I repeat that when I do the same to insert events this works fine. I've search a lot and tried a lot of possibilities and I can't do it work. If you've an idea...


Use

gdata.calendar.data.CalendarEventFeed

Some objects in gdata python library have two versions and you cannot mix them together.

0

精彩评论

暂无评论...
验证码 换一张
取 消