在Google日历API中相遇

huangapple go评论89阅读模式
英文:

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 +&quot;T&quot;+startTime+&quot;+06:00&quot; );//&quot;2020-05-05T11:00:00+06:00&quot;);
EventDateTime start = new EventDateTime()
    .setDateTime(startDateTime)
    .setTimeZone(&quot;Asia/Dhaka&quot;);
event.setStart(start);

DateTime endDateTime = new DateTime(date +&quot;T&quot;+endTime+&quot;+06:00&quot;);//&quot;2020-05-05T12:00:00+06:00&quot;);
EventDateTime end = new EventDateTime()
    .setDateTime(endDateTime)
    .setTimeZone(&quot;Asia/Dhaka&quot;);
event.setEnd(end);

String[] recurrence = new String[] {&quot;RRULE:FREQ=DAILY;COUNT=1&quot;};
event.setRecurrence(Arrays.asList(recurrence));

EventAttendee attendees[];

attendees = new EventAttendee[allAttendees.size()];

for(int i=0; i&lt;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(&quot;email&quot;).setMinutes(24 * 60),
    new EventReminder().setMethod(&quot;popup&quot;).setMinutes(10),
};


Event.Reminders reminders = new Event.Reminders()
    .setUseDefault(false)
    .setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);

String calendarId = &quot;primary&quot;;

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(&quot;What is meeting ID? = &quot;+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(&quot;eventHangout&quot;); // Non-G suite user
CreateConferenceRequest createConferenceReq = new CreateConferenceRequest();
createConferenceReq.setRequestId(&quot;3whatisup3&quot;); // 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 = &quot;primary&quot;;
// 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(&quot;What is meeting ID? = &quot;+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 +&quot;T&quot;+startTime+&quot;+06:00&quot; );//&quot;2020-05-05T11:00:00+06:00&quot;);
EventDateTime start = new EventDateTime()
.setDateTime(startDateTime)
.setTimeZone(&quot;Asia/Dhaka&quot;);
event.setStart(start);
DateTime endDateTime = new DateTime(date +&quot;T&quot;+endTime+&quot;+06:00&quot;);//&quot;2020-05-05T12:00:00+06:00&quot;);
EventDateTime end = new EventDateTime()
.setDateTime(endDateTime)
.setTimeZone(&quot;Asia/Dhaka&quot;);
event.setEnd(end);
String[] recurrence = new String[] {&quot;RRULE:FREQ=DAILY;COUNT=1&quot;};
event.setRecurrence(Arrays.asList(recurrence));
/*  s1 = &quot;abc@gmail.com&quot;;
s2 = &quot;xyz@gmail.com&quot;;
EventAttendee[] attendees = new EventAttendee[] {
new EventAttendee().setEmail(s1),
new EventAttendee().setEmail(s2),
};*/
EventAttendee attendees[];
attendees = new EventAttendee[allAttendees.size()];
for(int i=0; i&lt;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(&quot;email&quot;).setMinutes(24 * 60),
new EventReminder().setMethod(&quot;popup&quot;).setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
.setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
ConferenceSolutionKey conferenceSKey = new ConferenceSolutionKey();
conferenceSKey.setType(&quot;hangoutsMeet&quot;); // Non-G suite user
CreateConferenceRequest createConferenceReq = new CreateConferenceRequest();
createConferenceReq.setRequestId(&quot;3whatisup3&quot;); // ID generated by you
createConferenceReq.setConferenceSolutionKey(conferenceSKey);
ConferenceData conferenceData = new ConferenceData();
conferenceData.setCreateRequest(createConferenceReq);
event.setConferenceData(conferenceData);
String calendarId = &quot;primary&quot;;
try {
event = service.events().insert(calendarId, event).setConferenceDataVersion(1).execute();
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf(&quot;Event created: %s\n&quot;, event.getHtmlLink());
System.out.printf(&quot;Hangout Link %s\n&quot;, event.getHangoutLink());

答案3

得分: 0

@Jose Vasquez的回答是正确的,除了一点。
我将这行代码

conferenceSKey.setType(&quot;eventHangout&quot;);

更改为这样

conferenceSKey.setType(&quot;hangoutsMeet&quot;);

然后一切都正常工作了。

英文:

@Jose Vasquez's answer is right except for one thing.
I changed this line

conferenceSKey.setType(&quot;eventHangout&quot;);

to this

conferenceSKey.setType(&quot;hangoutsMeet&quot;); 

and then everything works fine.

huangapple
  • 本文由 发表于 2020年9月9日 06:03:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63802113.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定