Hello,
I use the entry id of the event to retrieve the original event, which works
well, clone it to a patch event, set start time and end time of the patch
event, update the patch event to the original one. It occurs an error, which is
printed in logcat of Eclipse as
'com.google.api.client.http.HttpResponseException: 500 Internal Server Error'.
Any operation of a event without time update is fine so far.
But as long as the request contains an update of start time or end time, it
returns a 500 Internal Server Error.
According to the documentation
http://code.google.com/apis/gdata/docs/2.0/reference.html#PartialUpdate, a
PATCH request is available instead of PUT request,
I have attached the Java file, the method with problem is
executePatchEventRelativeToOriginal(). This problem is reported by many
developers since April of this year.
Please help.
Thank you
--
You received this message because you are subscribed to the Google
Groups "Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/calendar/community/forum.html
package com.google.calendar.api;
import java.io.IOException;
import com.google.api.client.googleapis.xml.atom.AtomPatchRelativeToOriginalContent;
import com.google.api.client.googleapis.xml.atom.GoogleAtom;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.xml.atom.AtomContent;
import com.google.api.client.http.xml.atom.AtomParser;
import com.google.api.client.xml.XmlNamespaceDictionary;
public class CalendarClient {
/** Whether to enable debugging. */
public static final boolean DEBUG = true;
static final XmlNamespaceDictionary DICTIONARY =
new XmlNamespaceDictionary()
.set("", "http://www.w3.org/2005/Atom")
.set("batch", "http://schemas.google.com/gdata/batch")
.set("gd", "http://schemas.google.com/g/2005");
private final HttpRequestFactory requestFactory;
public CalendarClient(HttpRequestFactory requestFactory) {
this.requestFactory = requestFactory;
}
public void initializeParser(HttpRequest request) {
AtomParser parser = new AtomParser();
parser.namespaceDictionary = DICTIONARY;
request.addParser(parser);
}
public void executeDelete(CalendarUrl url) throws IOException {
HttpRequest request = requestFactory.buildDeleteRequest(url);
request.headers.ifMatch = "*";
request.execute().ignore();
}
Entry executeInsert(Entry entry, CalendarUrl url) throws IOException {
AtomContent content = new AtomContent();
content.namespaceDictionary = DICTIONARY;
content.entry = entry;
HttpRequest request = requestFactory.buildPostRequest(url, content);
return request.execute().parseAs(entry.getClass());
}
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(original.getEditLink()), content);
request.headers.ifMatch = "*";
return request.execute().parseAs(updated.getClass());
}
<F extends Feed> F executeGetFeed(CalendarUrl url, Class<F> feedClass) throws IOException {
url.fields = GoogleAtom.getFieldsFor(feedClass);
HttpRequest request = requestFactory.buildGetRequest(url);
return request.execute().parseAs(feedClass);
}
<E extends Entry> E executeGetEntry(CalendarUrl url, Class<E> eventClass) throws IOException{
url.fields = GoogleAtom.getFieldsFor(eventClass);
HttpRequest request = requestFactory.buildGetRequest(url);
return request.execute().parseAs(eventClass);
}
public CalendarEntry executeInsertCalendar(CalendarEntry entry, CalendarUrl url)
throws IOException {
return (CalendarEntry) executeInsert(entry, url);
}
public EventEntry executeInsertEvent(EventEntry entry, CalendarUrl url)
throws IOException {
return (EventEntry) executeInsert(entry, url);
}
public CalendarEntry executePatchCalendarRelativeToOriginal(
CalendarEntry updated, CalendarEntry original) throws IOException {
return (CalendarEntry) executePatchRelativeToOriginal(updated, original);
}
public EventEntry executePatchEventRelativeToOriginal(
EventEntry updated, EventEntry original) throws IOException {
return (EventEntry) executePatchRelativeToOriginal(updated, original);
}
public CalendarFeed executeGetCalendarFeed(CalendarUrl url) throws IOException {
return executeGetFeed(url, CalendarFeed.class);
}
public EventFeed executeGetEventFeed(CalendarUrl url) throws IOException {
return executeGetFeed(url, EventFeed.class);
}
public EventEntry executeGetEventEntry(CalendarUrl url) throws IOException {
return executeGetEntry(url, EventEntry.class);
}
}