无法为现有 Google 日历活动创建 Google 会议

Unable to create a Google meet conference for existing Google calendar event

我有一个可以在 Google 日历中正确生成事件的应用程序,现在我希望能够通过为它生成 Google 会议 link 来修改任何事件。理想情况下,我想在没有任何日历事件的情况下生成 Google 会议 link,但据我研究,目前唯一的方法是将其创建为 Google 日历事件的一部分。

我按照 https://developers.google.com/calendar/create-events?hl=en_US#java 中的步骤进行了操作,并得出了以下函数:

(defn add-meet-link-to-calendar-event
  "Adds a meet link to a calendar event."
  [google-ctx calendarId input-event]
  (if input-event
    (let [calendar-service (build-calendar-service google-ctx)
          events           (doto (.events ^Calendar calendar-service)
                             assert)
          conf-req-data (doto (CreateConferenceRequest.)
                          (.setRequestId (generate-random-string))
                          (.setConferenceSolutionKey (.setType (ConferenceSolutionKey.)
                                                               "hangoutsMeet")))
          conference-data (doto (ConferenceData.)
                            (.setCreateRequest conf-req-data)
                            )
          event (doto input-event
                        (.setConferenceData conference-data)
                        (.set "conferenceDataVersion" 1)
                        (.set "sendNotifications" true)
                        )
          eventId (get event "id")
          adding-link   (.patch events calendarId eventId event)]
      (prn "Before executing at add-meet-link-to-calendar-event" calendarId eventId event events)
      (.execute adding-link))))

作为此函数输入事件的一部分,我从另一个函数传递以下输出,该函数从 Google 日历检索事件 object:

{"attendees" [{"email" "jjj@company.com", 
"responseStatus" "needsAction"} 
{"email" "main@company.com", 
"organizer" true, 
"responseStatus" "accepted", 
"self" true}], 
"created" #object[com.google.api.client.util.DateTime 0x686d6e12 "2020-10-26T15:27:49.000Z"], 
"creator" {"email" "main@company.com", 
"self" true}, 
"end" {"dateTime" #object[com.google.api.client.util.DateTime 0x5a909950 "2020-10-24T22:30:00.000+02:00"]}, 
"etag" "\"3207454201190000\"", 
"htmlLink" "https://www.google.com/calendar/event?eid=M25wb2RtbnNsNWN2N3E3MGVsc2RvYTQwc2ogbmFpaGFAdWJpa2FyZSAAAA", 
"iCalUID" "3npodmnsl5cv7q70elsdoaAAAA@google.com", 
"id" "3npodmnsl5cv7q70elsdoaAAAA", 
"kind" "calendar#event", 
"organizer" {"email" "main@company.com", "self" true}, 
"reminders" {"useDefault" true}, 
"sequence" 0, 
"start" {"dateTime" #object[com.google.api.client.util.DateTime 0x7bcdfc0e "2020-10-24T22:00:00.000+02:00"]}, 
"status" "confirmed", 
"summary" "Another meet test", 
"updated" #object[com.google.api.client.util.DateTime 0xd4057 "2020-10-26T15:45:00.595Z"]}

我已经测试过像 summary 这样的值可以更新,因此 patch 调用似乎有效。但即使添加 conferenceDataVersionconferenceData 似乎也没有改变事件。

如果我手动更改Google日历中的事件我可以看到会议详细信息顺便添加到事件中。

根据 Calendar API Events Resource documentation:

hangoutLink > An absolute link to the Google+ hangout associated with this event. Read-only.

所以基本上,您不能通过日历API更改hangoutLink

您可以做的是在 Google 问题跟踪器 here.

上给问题加注星标 ★

更新

您可以通过发出关注请求向事件添加 hangoutLink,但是,您 不能 更改 link,因为它是自动分配的:

请求

PATCH https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId?conferenceDataVersion=1

正文

{
  "conferenceData": {
    "createRequest": {
      "conferenceSolutionKey": {
        "type": "eventNamedHangout"
      },
      "requestId": "SOME_STRING"
    }
  }
}

参考

由于@ale13 (Meet in Google Calendar API) 提供的 link 中的信息,这就是我最终设法修复它的方法:

(defn add-meet-link-to-calendar-event
  "Adds a meet link to a calendar event."
  [google-ctx calendarId eventId]
  (if eventId
    (let [calendar-service (build-calendar-service google-ctx)
          events           (doto (.events ^Calendar calendar-service)
                             assert)
          conf-req-data (doto (CreateConferenceRequest.)
                          (.setRequestId (generate-random-string))
                          (.setConferenceSolutionKey (.setType (ConferenceSolutionKey.)
                                                               "hangoutsMeet")))
          conference-data (doto (ConferenceData.)
                            (.setCreateRequest conf-req-data)
                            )
          event (doto (Event.)
                        (.setConferenceData conference-data))
          adding-link   (.patch events calendarId eventId event)
          set-data-conf (.setConferenceDataVersion adding-link (int 1))
          ]
      (prn "Before executing" calendarId event)
      (.execute set-data-conf))))

所以这里的关键是 conferenceDataVersion 值不必作为会议数据正文的一部分提供。它是 setter (setConferenceDataVersion),必须在 patch 结果上调用。

通过此更改,可以从中提取与会议相关的不同 link 的完整事件数据。