Meet ใน Google Calendar API
ฉันจะเพิ่ม google meet ใน google calendar api ใน java ได้อย่างไร? โปรดช่วยฉันด้วย ฉันไม่เข้าใจเอกสารของ Googlehttps://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);
คำตอบ
ตอบ
คุณจะต้องใช้เอกสาร JAVA APIสำหรับ Google ปฏิทิน
คุณต้องสร้างคำขอ Meet ใหม่จากนั้นผนวกเข้ากับเหตุการณ์ปัจจุบันและก่อนหน้านั้นให้เปิดใช้งาน conferenceDataVersion โดยตั้งค่าเป็น 1 ก่อนที่จะใช้รหัสต่อไปนี้โปรดตรวจสอบว่าคุณได้ตั้งค่านี้แล้ว
รหัส
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 Calendar JAVA API: Event.setConferenceData
Google Calendar JAVA API: ConferenceData.setCreateRequest
Google Calendar JAVA API: CreateConferenceRequest.setRequestId
Google Calendar JAVA API: ConferenceSolutionKey.setType
Google Calendar JAVA API: Calendar.Events.Insert.setConferenceDataVersion สำคัญที่สุด
รหัสสุดท้ายที่ใช้งานได้สำหรับฉันมีให้ด้านล่าง
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));
/* s1 = "[email protected]";
s2 = "[email protected]";
EventAttendee[] attendees = new EventAttendee[] {
new EventAttendee().setEmail(s1),
new EventAttendee().setEmail(s2),
};*/
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);
ConferenceSolutionKey conferenceSKey = new ConferenceSolutionKey();
conferenceSKey.setType("hangoutsMeet"); // 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);
String calendarId = "primary";
try {
event = service.events().insert(calendarId, event).setConferenceDataVersion(1).execute();
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("Event created: %s\n", event.getHtmlLink());
System.out.printf("Hangout Link %s\n", event.getHangoutLink());