Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar API v3 batch update in python

I'm having trouble using the new Google Calendar API v3 python library. The documentation seems a bit sparse. I can authenticate and get events on a specific calendar. However, I would like to perform batch update as was possible with the gdata library:

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

There is an example here https://developers.google.com/google-apps/calendar/batch#example in html. But can I do it using the python library?

like image 880
eldorz Avatar asked Jun 22 '26 20:06

eldorz


1 Answers

There's generic Google API Python library batch instructions here. Try something like:

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)
like image 176
Jay Lee Avatar answered Jun 25 '26 09:06

Jay Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!