问题描述
如何在Java的Google Calendar API中添加Google Meet?请帮我.我不了解Google文档. https://developers.google.com/calendar/create-events .源代码在这里给出.在这里,我想使用用户的Gmail帐户创建事件.我没有任何G-suite帐户
How can I add google meet in google calendar api in java?Please help me. I haven't understood the google documentation.https://developers.google.com/calendar/create-events. The source code is given here. Here, I want to create event using users gmail account. I have not any G-suite account
Event event = new Event()
.setSummary(title)
.setLocation(location)
.setDescription(description);
DateTime startDateTime = new DateTime( date +"T"+startTime+"+06:00" );//"2020-05-05T11:00:00+06:00");
EventDateTime start = new EventDateTime()
.setDateTime(startDateTime)
.setTimeZone("Asia/Dhaka");
event.setStart(start);
DateTime endDateTime = new DateTime(date +"T"+endTime+"+06:00");//"2020-05-05T12:00:00+06:00");
EventDateTime end = new EventDateTime()
.setDateTime(endDateTime)
.setTimeZone("Asia/Dhaka");
event.setEnd(end);
String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=1"};
event.setRecurrence(Arrays.asList(recurrence));
EventAttendee attendees[];
attendees = new EventAttendee[allAttendees.size()];
for(int i=0; i<allAttendees.size(); i++){
// System.out.println(allAttendees.get(i));
attendees[i] = new EventAttendee().setEmail(allAttendees.get(i));
}
event.setAttendees(Arrays.asList(attendees));
EventReminder[] reminderOverrides = new EventReminder[] {
new EventReminder().setMethod("email").setMinutes(24 * 60),
new EventReminder().setMethod("popup").setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
.setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
String calendarId = "primary";
try {
abc = service.events().insert(calendarId, event);
} catch (IOException e) {
e.printStackTrace();
}
try {
event = service.events().insert(calendarId, event).execute();
} catch (IOException e) {
e.printStackTrace();
}
String meetingId = event.getHangoutLink();
System.out.println("What is meeting ID? = "+meetingId);
推荐答案
答案
您将需要使用 Google日历的JAVA API文档
您必须创建一个新的Meet请求,然后将其追加到当前事件,然后,将其设置为1来启用conferenceDataVersion.在使用以下代码之前,请确保您具有此设置.
You have to create a new Meet request and then append it to the current event and before that, enable the conferenceDataVersion by setting it to 1. Before using the following code make sure that you have this setup.
Event event = new Event()
.setSummary(title)
.setLocation(location)
.setDescription(description);
// Your previous code
/* The code needed - START */
ConferenceSolutionKey conferenceSKey = new ConferenceSolutionKey();
conferenceSKey.setType("eventHangout"); // Non-G suite user
CreateConferenceRequest createConferenceReq = new CreateConferenceRequest();
createConferenceReq.setRequestId("3whatisup3"); // ID generated by you
createConferenceReq.setConferenceSolutionKey(conferenceSKey);
ConferenceData conferenceData = new ConferenceData();
conferenceData.setCreateRequest(createConferenceReq);
event.setConferenceData(conferenceData); // attach the meeting to your event
/* The code needed - END */
String calendarId = "primary";
// There’s no need to declare the try-catch block twice
try {
/* Code changes - START */
// .setConferenceDataVersion(1) enables the creation of new meetings
event = service.events().insert(calendarId, event).setConferenceDataVersion(1).execute();
/* Code changes - END */
} catch (IOException e) {
e.printStackTrace();
}
String meetingId = event.getHangoutLink();
System.out.println("What is meeting ID? = "+meetingId);
参考文献
Google日历JAVA API:Event.setConferenceData
Google日历JAVA API:ConferenceData.setCreateRequest
Google日历JAVA API:CreateConferenceRequest.setRequestId
Google日历JAVA API:ConferenceSolutionKey.setType
Google日历JAVA API:Calendar.Events.Insert.setConferenceDataVersion 最重要
这篇关于在Google Calendar API中开会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!