简体   繁体   English

在 Google Calendar API 中开会

[英]Meet in Google Calendar API

How can I add google meet in google calendar api in java?如何在 Java 的 google 日历 api 中添加 google meet? Please help me.请帮我。 I haven't understood the google documentation.我还没有理解谷歌文档。 https://developers.google.com/calendar/create-events . https://developers.google.com/calendar/create-events The source code is given here.源代码在这里给出。 Here, I want to create event using users gmail account.在这里,我想使用用户 gmail 帐户创建事件。 I have not any G-suite account我没有任何 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);

Answer回答

You will need to use the JAVA API Documentation for Google Calendar您将需要使用 Google 日历的JAVA API 文档

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 .您必须创建一个新的 Meet 请求,然后将其附加到当前事件中,在此之前,通过将其设置为 1 来启用会议数据版本。在使用以下代码之前,请确保您有此设置

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 谷歌日历 JAVA API:Event.setConferenceData

Google Calendar JAVA API: ConferenceData.setCreateRequest 谷歌日历 JAVA API: ConferenceData.setCreateRequest

Google Calendar JAVA API: CreateConferenceRequest.setRequestId 谷歌日历 JAVA API:CreateConferenceRequest.setRequestId

Google Calendar JAVA API: ConferenceSolutionKey.setType 谷歌日历 JAVA API: ConferenceSolutionKey.setType

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

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());

@Jose Vasquez's answer is right except for one thing. @Jose Vasquez 的回答是正确的,除了一件事。 I changed this line我改变了这条线

conferenceSKey.setType("eventHangout");

to this对此

conferenceSKey.setType("hangoutsMeet"); 

and then everything works fine.然后一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM