Google Calendar API - can only update an event once

I ran into the same problem as in this post:

Google Calendar api v3 update problem

Namely, as soon as I create an event and update it once using the Google Calendar API (v3), I can no longer update the event. When I try, I get a response of 400 - invalid. (FWIW I work in PHP).

Following the example above, I tried to solve the problem using etags (although, admittedly, my understanding of how they work is limited). In principle, when updating an event, the API returns a response that I now save in my database. Then, for subsequent (n> 1) updates, I pull the current file out of the database and include it in the http header:

Content-Type: application/json Authorization: OAuth [token] If-Match: [etag] 

The following is the heading for "Updating Entries" here: http://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning

Sidenote: In the google feed above, the If-Match title appears as

 If-Match: "S0wCTlpIIip7ImA0X0QI" 

with double quotes around etag. I store etags in a double-quoted database, just like I get them in the first update response. Do I need to avoid quotes or anything when adding to the header using curl_setopt / HTTPHEADER?

Despite the fact that this etag If-Match option is implemented, I still get the same 400 response - Invalid value. I know that my request authorities are valid because the first update is working fine. There are only some additional problems associated with subsequent updates.

Any help is greatly appreciated.

+4
source share
3 answers

When updating events, be sure to increase the sequence number field.

+14
source

I had the same problem. To increase the sequence number, you need to keep track of how many updates you have made, and include the next step in your update. For some reason, the first update does not require this, but subsequent updates require this.

Using the google php library for your second update for an event would look something like this (minus everything you update):

 $calendarID = ID_OF_YOUR_CALENDAR; $eventID = ID_OF_YOUR_EVENT; $event = new Google_Event(); $event->setSequence('2'); $calEvent = $cal->events->update($calendarID $eventID, $event); 
0
source

This is how I do it. Retrieve the record from Google so that it already installs the latest Etag set and increment the sequence by one and update the record.

How I use java, so the following example with java:

 com.google.api.services.calendar.model.Event googleCalendarEvent = service.events().get(clientCalendarEvent.getCalendar().getCalendarKey(),clientCalendarEvent.getEventKey()).execute(); updateGoogleCalendarEvent(clientCalendarEvent, googleCalendarEvent); googleCalendarEvent.setSequence(googleCalendarEvent.getSequence() + 1); com.google.api.services.calendar.model.Event event = service .events() .update(clientCalendarEvent.getCalendar().getCalendarKey(), clientCalendarEvent.getEventKey(), googleCalendarEvent).execute(); 
0
source

Source: https://habr.com/ru/post/947409/


All Articles