[英]How can I use the Google Calendar API for Java to delete an event on my Google Calendar?
我已经搜索了高低,找到了一个例子,因为我正在尝试的似乎并不起作用。 我收到此错误:
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);
它被切碎和改变太多了,我不知道我现在在哪里。 有谁遇到过这个问题? 如果是这样,你是如何克服它的? 有没有人得到一些代码的例子,因为谷歌只在他们的解释中提供一行代码。
你需要做的唯一事情是在你的活动上有一个“处理”,有不同的方式来获得它,如果你想要删除日历中的特定事件,我会告诉你我该怎么做
String title = "Event title that i want to delete";
try{
URL calendarUrl= new URL(calendar.getLink(Link.Rel.ALTERNATE, Link.Type.ATOM).getHref());
CalendarEventFeed resultFeed = service.getFeed(calendarUrl, CalendarEventFeed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEventEntry entry = resultFeed.getEntries().get(i);
if(entry.getTitle().getPlainText().equals(title)){
entry.delete();
break;
}
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (ServiceException e) {
e.printStackTrace();
}
因此,您只需要设置特定日历的标题(或任何设置),如果您不知道如何在之前已创建的日历上获取“句柄”,我可以向您解释如何操作。 在我的代码中,“calendar”是一个ClendarEntry。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.