Google Calendar: No way to update event

72 views
Skip to first unread message

Mike

unread,
Sep 2, 2011, 7:50:45 PM9/2/11
to google-api-...@googlegroups.com
Hi,

I'm following the Android sample on how to use the Google Calendar API but I cannot find a way to update an event.

I am fetching the events and looping through to get the one I want and then getting the edit link. But from there I'm sort of stuck. It seems that I need to use something similar to executePatchRelativeToOriginal, which can be found for calendar feeds.

Any suggestions?


Mike

Mike

unread,
Sep 11, 2011, 9:44:46 AM9/11/11
to google-api-...@googlegroups.com
For those having the same problems, here's a solution.

Update events need to be made with a PUT request. And you need to set the If-Match/etag correctly (I will disregard if someone has updated the event so I set it to "*"). You will need to make the following additions to the Google API Java Client:

In your GDataClient.java add the following method:

  protected final <T> T executePut(GoogleUrl url, AbstractHttpContent content, Class<T> parseAsType, String etag) throws IOException {
    prepareUrl(url, parseAsType);
    HttpRequest request = getRequestFactory().buildPutRequest(url, content);
    setIfMatch(request, etag);
    return execute(request).parseAs(parseAsType);
  }

In your GDataXmlClient.java add the following method:

  protected final <T> T executePut(GoogleUrl url, T content, String etag) throws IOException {
      AtomContent atomContent = AtomContent.forEntry(namespaceDictionary, content);
      @SuppressWarnings("unchecked")
      Class<T> parseAsType = (Class<T>) content.getClass();
      return executePut(url, atomContent, parseAsType, etag);
  }

In your CalendarClient.java add this method to the EventCollection class:

    /** Update request. */
    public class UpdateRequest {
      public EventEntry execute(EventEntry updated) throws IOException {
CalendarUrl url = new CalendarUrl(updated.getEditLink());
        return executePut(url, updated, "*");
      }
    }

This will enable you to make update requests like this:

    EventEntry entry = existingEntry.clone();
    // now make any changes to you entry
    client.eventFeed().update().execute(entry);

Good luck.


Mike
Reply all
Reply to author
Forward
0 new messages