英文:
Meet in Google Calendar API
问题
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);
英文:
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);
答案1
得分: 7
答案
您需要使用JAVA API文档来操作Google日历。
您需要创建一个新的Meet请求,然后将其附加到当前事件之前,需要将conferenceDataVersion设置为1。在使用下面的代码之前,请确保您已经完成了设置步骤。
代码
Event event = new Event()
.setSummary(title)
.setLocation(location)
.setDescription(description);
// 之前的代码
/* 所需的代码 - 开始 */
ConferenceSolutionKey conferenceSKey = new ConferenceSolutionKey();
conferenceSKey.setType("eventHangout"); // 非G Suite用户
CreateConferenceRequest createConferenceReq = new CreateConferenceRequest();
createConferenceReq.setRequestId("3whatisup3"); // 您生成的ID
createConferenceReq.setConferenceSolutionKey(conferenceSKey);
ConferenceData conferenceData = new ConferenceData();
conferenceData.setCreateRequest(createConferenceReq);
event.setConferenceData(conferenceData); // 将会议附加到您的事件
/* 所需的代码 - 结束 */
String calendarId = "primary";
// 没有必要两次声明try-catch块
try {
/* 代码更改 - 开始 */
// .setConferenceDataVersion(1) 启用新会议的创建
event = service.events().insert(calendarId, event).setConferenceDataVersion(1).execute();
/* 代码更改 - 结束 */
} catch (IOException e) {
e.printStackTrace();
}
String meetingId = event.getHangoutLink();
System.out.println("会议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 最重要的部分
英文:
Answer
You will need to use the JAVA API Documentation for Google Calendar
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.
Code
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);
References
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 The most important
答案2
得分: 3
以下是您所提供代码的翻译:
最终适用于我的代码如下。
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++){
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"); // 非 G Suite 用户
CreateConferenceRequest createConferenceReq = new CreateConferenceRequest();
createConferenceReq.setRequestId("3whatisup3"); // 由您生成的 ID
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("已创建事件:%s\n", event.getHtmlLink());
System.out.printf("Hangout 链接:%s\n", event.getHangoutLink());
请注意,由于代码中包含变量和方法调用,我已保留原始的变量、方法和注释。如有任何问题或需要进一步协助,请随时提问。
英文:
The final workable code for me is given below.
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 = "abc@gmail.com";
s2 = "xyz@gmail.com";
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());
答案3
得分: 0
@Jose Vasquez的回答是正确的,除了一点。
我将这行代码
conferenceSKey.setType("eventHangout");
更改为这样
conferenceSKey.setType("hangoutsMeet");
然后一切都正常工作了。
英文:
@Jose Vasquez's answer is right except for one thing.
I changed this line
conferenceSKey.setType("eventHangout");
to this
conferenceSKey.setType("hangoutsMeet");
and then everything works fine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论