且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google Calendar API v3-更新事件

更新时间:2022-10-18 14:54:52

文档对此确实很粗略,但是似乎您每次执行更新时都必须增加sequence属性.这是一个版本控制机制.

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

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

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