在 Google 日历 API 中开会

Posted

技术标签:

【中文标题】在 Google 日历 API 中开会【英文标题】:Meet in Google Calendar API 【发布时间】:2020-12-27 07:46:24 【问题描述】:

如何在 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);

【问题讨论】:

嗨!如果您能提供一些您已经编写的代码,那将非常有帮助 给出源代码 【参考方案1】:

@Jose Vasquez 的回答是正确的,除了一件事。 我改变了这一行

conferenceSKey.setType("eventHangout");

到这里

conferenceSKey.setType("hangoutsMeet"); 

然后一切正常。

【讨论】:

【参考方案2】:

下面给出了对我来说最终可行的代码。

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

【讨论】:

如果您能解释为什么这是一个适合您的解决方案,您需要做什么,将会很有帮助。所以像我这样的人稍后会看到你的代码。 上面的代码是我的解决方案,因为我想在创建日历事件时创建谷歌会议链接。通过使用此代码,Google Meet 链接成功创建与日历事件。 从哪里生成 id?【参考方案3】:

回答

您需要将 JAVA API Documentation 用于 Google 日历

您必须创建一个新的 Meet 请求,然后将其附加到当前事件中,在此之前,通过将其设置为 1 来启用 ConferenceDataVersion。在使用以下代码之前,请确保您拥有此 setup。

代码

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 最重要的

【讨论】:

我使用了以下依赖项。实施('com.google.api-client:google-api-client-android:1.23.0')排除组:'org.apache.httpcomponents'实施('com.google.apis:google-api-services -日历:v3-rev305-1.23.0')排除组:'org.apache.httpcomponents' 您能否详细描述一下您遇到了什么错误? 是的,兄弟。您的代码正在运行。非常感谢。愿上帝保佑你。 很高兴为您提供帮助!如果可以的话,出于文档目的,请接受对您有帮助的答案 - 它可以帮助将来遇到相同问题的其他人也找到解决方案。

以上是关于在 Google 日历 API 中开会的主要内容,如果未能解决你的问题,请参考以下文章

团队如何开会,开会准则

如何开会 -- 故障处理

软件详细设计的开会记录(补)

98多人开会,是为了达成共识,不是为了讨论问题

upc 9328 开会

程序员都讨厌开会?