在 Google 日历 API 中开会

Tui*_*Spl 7 java google-calendar-api google-meet

如何在java中的google calendar api中添加google meet?请帮我。我还没看懂谷歌文档。 https://developers.google.com/calendar/create-events。这里给出了源代码。在这里,我想使用用户 Gmail 帐户创建事件。我没有任何 G-suite 帐户

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);
Run Code Online (Sandbox Code Playgroud)

Jos*_*uez 7

回答

\n

您将需要使用Google 日历的JAVA API 文档

\n

您必须创建一个新的 Meet 请求,然后将其附加到当前活动,在此之前,将conferenceDataVersion 设置为 1 来启用它。在使用以下代码之前,请确保您已进行此设置

\n

代码

\n
Event event = new Event()\n                        .setSummary(title)\n                        .setLocation(location)\n                        .setDescription(description);\n\n// Your previous code\n\n/* The code needed - START */\n\nConferenceSolutionKey conferenceSKey = new ConferenceSolutionKey();\nconferenceSKey.setType("eventHangout"); // Non-G suite user\nCreateConferenceRequest createConferenceReq = new CreateConferenceRequest();\ncreateConferenceReq.setRequestId("3whatisup3"); // ID generated by you\ncreateConferenceReq.setConferenceSolutionKey(conferenceSKey);\nConferenceData conferenceData = new ConferenceData();\nconferenceData.setCreateRequest(createConferenceReq);\nevent.setConferenceData(conferenceData); // attach the meeting to your event\n\n/* The code needed - END */\n\nString calendarId = "primary";\n\n// There\xe2\x80\x99s no need to declare the try-catch block twice\n\ntry {\n    /* Code changes - START */\n\n    // .setConferenceDataVersion(1) enables the creation of new meetings\n    event = service.events().insert(calendarId, event).setConferenceDataVersion(1).execute();\n\n    /* Code changes - END */\n\n} catch (IOException e) {\n    e.printStackTrace();\n}\n\nString meetingId = event.getHangoutLink();\nSystem.out.println("What is meeting ID? = "+meetingId);\n
Run Code Online (Sandbox Code Playgroud)\n

参考

\n

Google 日历 JAVA API: Event.setConferenceData\n

\n

Google 日历 JAVA API:ConferenceData.setCreateRequest

\n

Google 日历 JAVA API:CreateConferenceRequest.setRequestId

\n

Google 日历 JAVA API:ConferenceSolutionKey.setType

\n

Google Calendar JAVA API:Calendar.Events.Insert.setConferenceDataVersion 最重要

\n

  • 乐意效劳!如果可以的话,出于文档目的,请接受对您有帮助的答案 - 它也可以帮助将来遇到相同问题的其他人找到解决方案。 (2认同)