2014-12-04 94 views
2

我在使用新的Google Calendar API v3 python庫時遇到問題。該文件似乎有點稀疏。我可以在特定日曆上進行身份驗證並獲取活動。不過,我想執行批量更新爲使用GData庫是可能的:python中的Google Calendar API v3批量更新

# example from gdata 
# feed that holds all the batch rquest entries 
    request_feed = gdata.calendar.data.CalendarEventFeed() 
# add the update entries to the batch feed 
    request_feed.AddUpdate(entry=updateEntry1) 
    request_feed.AddUpdate(entry=updateEntry2) 
# submit the batch request to the server 
    response_feed = self.cal_client.ExecuteBatch(request_feed, gdata.calendar.client.DEFAULT_BATCH_URL) 

有一個例子在這裏HTML https://developers.google.com/google-apps/calendar/batch#example。但我可以使用python庫嗎?

回答

2

有通用的Google API Python庫批量指令here。嘗試像這樣:

from apiclient.http import BatchHttpRequest 

def insert_event(request_id, response, exception): 
    if exception is not None: 
    # Do something with the exception 
    pass 
    else: 
    # Do something with the response 
    pass 

service = build('calendar', 'v3') 

batch = BatchHttpRequest(callback=insert_event) 

batch.add(service.events().quickAdd(calendarId="[email protected]", 
    text="Lunch with Jim on Friday")) 
batch.add(service.events().quickAdd(calendarId="[email protected]", 
    text="Dinner with Amy on Saturday")) 
batch.add(service.events().quickAdd(calendarId="[email protected]", 
    text="Breakfast with John on Sunday")) 
batch.execute(http=http) 
+0

謝謝!這看起來就像是這樣。 – eldorz 2014-12-07 05:06:05

+0

@JayLee你可以請讓我知道如何從批處理請求呈現整個響應HTML ....我正在處理與Gmail的API,我得到了insert_event函數的響應,但我無法呈現它... 。 – 2015-04-28 08:24:31