Java 如何在Android上编辑谷歌日历事件?
我想使用谷歌日历API编辑事件。 在示例中,有一个用于编辑日历的代码:Java 如何在Android上编辑谷歌日历事件?,java,android,google-calendar-api,Java,Android,Google Calendar Api,我想使用谷歌日历API编辑事件。 在示例中,有一个用于编辑日历的代码: Entry executePatchRelativeToOriginal(Entry updated, Entry original) throws IOException { AtomPatchRelativeToOriginalContent content = new AtomPatchRelativeToOriginalContent(); content.namespaceDictionary = DI
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());
如果我想编辑日历,它可以工作,但不适用于编辑事件:我有例外:
09-11 17:29:13.516: WARN/System.err(15787): com.google.api.client.http.HttpResponseException: 403 Forbidden
当然我有权利编辑这个事件。
此外,删除日历的相同方法也适用于删除事件。
删除功能:
public void executeDelete(Entry entry) throws IOException {
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(entry.getEditLink()));
request.execute().ignore();
}
有什么想法吗?问题解决了!我在Atom中使用了HTTP PUT而不是HTTP补丁,并修改了 原始事件,而不是创建对象的另一个实例 以下是工作代码:
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());}