Google Calendar API: Cannot get Google Meet link for newly created event with service account access in PHP

Viewed 789

I cannot get this to work, have been looking at several other related questions and answers and I think the problem is somewhere in the fact that I'm using a service account for this. The situation is:

  • I have a Google Service Account and a Google Calendar ID (access with service key)
  • I can create a new event in the calendar without any problem.
  • When I also try to get a Google Meet link, I get an error: "Invalid conference type value"

This my code:

$client = new Google_Client();

$client->setAuthConfig(xxx);
$client->setScopes("https://www.googleapis.com/auth/calendar");

$service = new Google_Service_Calendar($client);
    
$event = new Google_Service_Calendar_Event(array(
    "description" => "Test", 
    "start" => array(
        "dateTime" => "2021-09-01T09:00",
        "timeZone" => "Europe/Brussels",
    ),
    "end" => array(
        "dateTime" => "2021-09-01T10:00",
        "timeZone" => "Europe/Brussels",
    )           
));

// add google meet link

$solution_key = new Google_Service_Calendar_ConferenceSolutionKey();
$solution_key->setType("hangoutsMeet");
$confrequest = new Google_Service_Calendar_CreateConferenceRequest();
$confrequest->setRequestId("X".time());
$confrequest->setConferenceSolutionKey($solution_key);
$confdata = new Google_Service_Calendar_ConferenceData();
$confdata->setCreateRequest($confrequest);
$event->setConferenceData($confdata);

$event = $service->events->insert($google_calendar_id, $event, array('conferenceDataVersion' => 1));

Without the parameter "array('conferenceDataVersion' => 1)" the event is being created. I'm almost sure it has something to do with access rights, but I don't know where to look anymore...

1 Answers

"Invalid conference type value"

Means that you are sending a conference type

$solution_key->setType("hangoutsMeet");

Which is not allowed for the calendar you are using

$google_calendar_id,

Try and run a calendar.get and send the calendar id you are trying to use.

Request:

 $service->calendar->get($google_calendar_id)

Response:

{
 "kind": "calendar#calendar",
 "etag": "\"j3g2ipQvsbvz0_YlxYi3Ml2Fd7A\"",
 "id": "xxxxx@gmail.com",
 "summary": "Linda Lawton ",
 "description": "test",
 "timeZone": "Europe/Copenhagen",
 "conferenceProperties": {
  "allowedConferenceSolutionTypes": [
   "hangoutsMeet"
  ]
 }
}

The allowedConferenceSolutionTypes in the response will tell you which type you are allowed to use for that calendar.

As far as the service account goes just make sure you have domain wide delegation set up and that you are delegating to a user on the domain and this shouldn't be any issues.

$client->setSubject($user_to_impersonate);
Related