jbarren
jbarren

Reputation: 65

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

I have an application that can correctly generate events in Google calendar, and now I want to be able to modify any event by generating a Google meet link for it. Ideally I would like to generate Google meet links without any calendar events, but as far as I researched the only way for now is to create it as part of a Google calendar event.

I have followed the steps in https://developers.google.com/calendar/create-events?hl=en_US#java and I came up with the following function:

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

As part of the input event for this function, I'm passing the following output from another function that retrieves the event object from Google calendar:

{"attendees" [{"email" "[email protected]", 
"responseStatus" "needsAction"} 
{"email" "[email protected]", 
"organizer" true, 
"responseStatus" "accepted", 
"self" true}], 
"created" #object[com.google.api.client.util.DateTime 0x686d6e12 "2020-10-26T15:27:49.000Z"], 
"creator" {"email" "[email protected]", 
"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" "[email protected]", 
"id" "3npodmnsl5cv7q70elsdoaAAAA", 
"kind" "calendar#event", 
"organizer" {"email" "[email protected]", "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"]}

I have tested that values like summary can be updated so the patch call seems to work. But even adding the conferenceDataVersion and the conferenceData does not seem to make a change in the event.

If I manually change the event in Google calendar I can see that the conference details are added to the event by the way.

Upvotes: 0

Views: 758

Answers (2)

jbarren
jbarren

Reputation: 65

This is how I managed to fix it in the end, thanks to the info from the link provided by @ale13 (Meet in Google Calendar API):

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

So the key thing here is that the conferenceDataVersion value does not have to be provided as part of the body of the conference data. It is a setter (setConferenceDataVersion) that has to be called onto the patch result.

With this change a full event data is received where the different links related to the conference can be extracted from.

Upvotes: 0

ale13
ale13

Reputation: 6072

According to the Calendar API Events Resource documentation:

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

So essentially, you cannot change the hangoutLink through the Calendar API.

What you can do instead is to star ★ the issue on Google Issue Tracker here.

Update

You can add a hangoutLink to an event by making the follow request, however, you cannot change the link as it is assigned automatically:

Request

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

Body

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

Reference

Upvotes: 1

Related Questions