Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Calendar API v3 - Update Event

I'm using google-api-ruby-client for working with Google Calendar API v3.

The only problem I'm facing is with updating an event twice.

It has been discussed here before (Google Calendar api v3 re-update issue) but without ruby client and no answer.

When I add a new event I get an ID and an ETAG. I use ID to update the event and I get a new ETAG. Now If I try to update 2nd time, it doesn't update and sends 400 error with message "Invalid Value".

I have to send latest ETAG when updating 2nd time but I'm not sure how to send that when working with google-api-ruby-client.

Here's the code:

    event = {
      'summary' => "Summary",
      'location' => "Location",
      'description' => "Description",
      'start' => {
      'dateTime' => @entry.from_date
     },
      'end' => {
        'dateTime' => @entry.to_date
      }
    }

    result = client.execute(:api_method => service.events.update,
                    :parameters => {'calendarId' => @entry.calendar.gid, 'eventId'=>@entry.gid},
                    :body => JSON.dump(event),
                    :headers => {'Content-Type' => 'application/json'})
like image 787
Sharj Avatar asked Apr 26 '12 11:04

Sharj


1 Answers

The docs are really sketchy on this but it seems you have to increment the sequence property each time you do an update. It's a revision control mechanism.

http://www.kanzaki.com/docs/ical/sequence.html

like image 79
Lachlan Cotter Avatar answered Sep 22 '22 19:09

Lachlan Cotter