简体   繁体   中英

How to edit google calendar event on Android?

I want to edit event using Google Calendar API. In example there was a code to edit calendar:

Entry executePatchRelativeToOriginal(Entry updated, Entry original) throws IOException {
   AtomPatchRelativeToOriginalContent content = new AtomPatchRelativeToOriginalContent();
   content.namespaceDictionary = DICTIONARY;
   content.originalEntry = original;
   content.patchedEntry = updated;
   HttpRequest request =
      requestFactory.buildPatchRequest(new GenericUrl(updated.getEditLink()), content);
   return request.execute().parseAs(updated.getClass());

And it works if I want edit calendar, but it don't work with edit event: I have exception:

09-11 17:29:13.516: WARN/System.err(15787): com.google.api.client.http.HttpResponseException: 403 Forbidden

Of course I have rigths to edit event. Moreover, the same method to delete calendar works with delete event. Delete function:

public void executeDelete(Entry entry) throws IOException {
    HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(entry.getEditLink()));
    request.execute().ignore();
}

Any ideas?

Problem solved! I used HTTP PUT instead of HTTP PATCH in Atom, and modified the original event instead of create another instance of the object.

Here is a working code:

public EventEntry executePutUpdateEvent(EventEntry updated) throws IOException {
AtomContent content = new AtomContent();
content.namespaceDictionary = DICTIONARY;
content.entry = updated;
HttpRequest request =
    requestFactory.buildPutRequest(new GenericUrl(updated.getEditLink()), content);
return request.execute().parseAs(updated.getClass());}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM