[英]How to create new event in Google Calendar API with java in NetBeans
I followed the quickstart guide that Google provides on Calendar API https://developers.google.com/google-apps/calendar/quickstart/java but they dont explain how to create a new event. 我遵循了Google在Calendar API上提供的快速入门指南https://developers.google.com/google-apps/calendar/quickstart/java,但他们没有解释如何创建新事件。 I found this snippet of code online
我在网上找到了这段代码
public void createEvent(Calendar cal){
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());
}
But it didn't help me, i got an error in the Event createdEvent = cal.events() section as events() doesn't exist. 但这对我没有帮助,因为events()不存在,所以在event createdEvent = cal.events()部分出现了错误。 Any help is much appreciated, thank you.
非常感谢您的任何帮助,谢谢。
At the bottom of your link to the documentation there is a link to Create Events. 在文档链接的底部,有一个指向创建事件的链接。 I won't duplicate the entire page here, but the gist is that you need to Create an
Event
object (perhaps called MyNewEvent
), populate it, and then call: 我不会在此处复制整个页面,但是要点是,您需要创建一个
Event
对象(也许称为MyNewEvent
),填充它,然后调用:
MyNewEvent = service.events().insert("Some Calendar Id", MyNewEvent).execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.