使用oauth2和calendar api v3将事件插入谷歌日历api的示例

时间:2013-04-06 23:50:38

标签: java google-calendar-api google-api-java-client

我尝试了很多方法,使用oauth2和日历Api v3将事件插入谷歌日历。但我找不到任何例子。

1 个答案:

答案 0 :(得分:2)

public void createEvent(Calendar cal) throws IOException {       

Event event = new Event();
event.setSummary("Event name here");
event.setLocation("event place here");

Date startDate = new Date();
Date endDate = new Date(startDate.getTime() + 3600000);
DateTime start = new DateTime(startDate, TimeZone.getTimeZone("UTC"));
event.setStart(new EventDateTime().setDateTime(start));
DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC"));
event.setEnd(new EventDateTime().setDateTime(end));
Event createdEvent = cal.events().insert("primary", event).execute();
System.out.println("Created event id: " + createdEvent.getId());
}

希望此代码段可以帮助您