google Calendar API (Java)

2019-08-31 06:45发布

问题:

How to get the Date/time for an Event I retrieve ?

CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("username@gmail.com", "pwd");
URL feedUrl = new URL("https://www.google.com/calendar/feeds/username@gmail.com/public/full");

CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setFullTextQuery("Query");
CalendarEventFeed myResultsFeed = myService.query(myQuery,
    CalendarEventFeed.class);

  for (int i=0; i < myResultsFeed.getEntries().size(); i++)
  {
    CalendarEventEntry firstMatchEntry = (CalendarEventEntry) myResultsFeed.getEntries().get(i);
    String myEntryTitle = firstMatchEntry.getTitle().getPlainText();
    System.out.println(myEntryTitle + " " + firstMatchEntry.getPlainTextContent());
    System.out.println(""+firstMatchEntry.getAuthors().get(0).getEmail());
    System.out.println(""+firstMatchEntry.getPublished());
    System.out.println(""+firstMatchEntry.getHtmlLink().getHref());
    System.out.println(""+firstMatchEntry.getStatus().getValue());
  }

I couldn't find a way to get any more useful info from a CalendarEventEntry.

LE: problem solved; after seeing this:

http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents

I got to this:

System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());

Good thing the examples are different depending on language.

回答1:

Problem solved; after seeing this:

http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingEvents

I got to this:

System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getStartTime());
System.out.println("start time = "+firstMatchEntry.getTimes().get(0).getEndTime());


标签: java calendar