How can I use the Google Calendar API for Java to delete an event in my Google Calendar?

I searched high and low to find an example, because what I'm trying doesn't seem to work. I get this error:

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)

Here is an example of the code I'm using:

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);

It has been shredded and altered so much that I'm not sure where I am now. Has anyone encountered this issue? If so, how did you overcome it? Someone got a sample code that works, since Google provides only one line of code in its explanation.

+3
source share
2 answers

Can you try

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

instead

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

?

, , , - "", . , ( ), . , .

+1

, , "" , , , ,

    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();
    }

( ) , , "" , , . "" - ClendarEntry.

+1

All Articles