java - 如何使用适用于 Java 的 Google 日历 API 删除我的 Google 日历上的 Activity ?

标签 java google-calendar-api

我到处搜索以找到示例,因为我正在尝试的方法似乎不起作用。我收到此错误:

com.google.gdata.util.InvalidEntryException: Bad Request
Invalid request URI

    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
    at com.google.gdata.client.Service.update(Service.java:1563)
    at com.google.gdata.client.Service.update(Service.java:1530)
    at com.google.gdata.client.GoogleService.update(GoogleService.java:583)
    at CalendarConnect.deleteEvent(CalendarConnect.java:37)
    at ProgMain.main(ProgMain.java:26)

这是我使用的代码示例:

CalendarService service = new CalendarService("Fourth Year Project");
             service.setUserCredentials(username, password);

             URL postUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
             CalendarEventEntry myEntry = new CalendarEventEntry();

             myEntry.setTitle(new PlainTextConstruct("TEST"));
             myEntry.setContent(new PlainTextConstruct("TEST"));

             DateTime startTime = DateTime.parseDateTime(StartDateTime);
             DateTime endTime = DateTime.parseDateTime(EndDateTime);
             When eventTimes = new When();
             eventTimes.setStartTime(startTime);
             eventTimes.setEndTime(endTime);
             myEntry.addTime(eventTimes);

             CalendarEventEntry insertedEntry = service.update(postUrl, myEntry);

             URL deleteUrl = new URL(insertedEntry.getEditLink().getHref());
             service.delete(deleteUrl);

它被切碎和改变了太多,以至于我不确定我现在在哪里。有没有人遇到过这个问题?如果是这样,你是如何克服它的?有没有人得到一些代码的例子,因为谷歌在他们的解释中只提供了一行代码。

最佳答案

你能试试吗

CalendarEventEntry insertedEntry = service.insert(postUrl, myEntry);

代替

CalendarEventEntry insertedEntry = service.update(postUrl, myEntry);

?

我认为您拥有的其余代码用于插入事件条目,您不能用它调用更新。如果您将其更改为插入,它将插入和删除该条目(如果有效)并且我看不到其中的一点。如果您尝试检索条目并将其删除,the post. 中有一些示例。

关于java - 如何使用适用于 Java 的 Google 日历 API 删除我的 Google 日历上的 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5918536/

相关文章:

java - 为什么小程序关闭服务器?

java - 如何根据Java中的组合框选项设置文本字段值?

使用 Sqlite 数据库的 Java 应用程序,无需向安装程序包提供现有数据库

perl - 使用 Perl 和 Net::OAuth2 将 POST 事件传输到 Google 日历

Java时间戳转换错误

java - 更新谷歌重复事件上的特定事件,而不会错过它在Java中的重复信息

jquery - 如何在 Fullcalendar Jquery 中将时间段选择限制为一天?

Android如何将google帐户传递给webview

java - Google 日历 API 共享示例

java - 如何将多个 jar 合并为一个?