2011-10-08 3 views
2

Google API를 사용하여 캘린더의 모든 이벤트를 삭제하려고합니다. 하나씩 이벤트를 삭제하면 작동하지만 매우 길기 때문에 최적화되지 않은 상태이므로 일정에 많은 항목을 삽입하는 데 사용하는 ExecuteBatch를 사용하여 동일한 작업을 시도합니다 (삽입 전에 잘 작동합니다) .Google Cal API 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' 

합니다. 많은 검색을 해보고 많은 가능성을 시도했지만 제대로 작동하지 않습니다. GDATA 파이썬 라이브러리에 당신이 아이디어를 한 경우 ...

답변

1

사용

gdata.calendar.data.CalendarEventFeed 

일부 개체가 두 가지 버전이 있고이 둘을 혼합 할 수 없습니다.