我无法让它工作,一直在查看其他几个相关的问题和答案,我认为问题出在我为此使用服务帐户这一事实中。情况是:
- 我有一个 Google 服务帐户和一个 Google 日历 ID(使用服务密钥访问)
- 我可以毫无问题地在日历中创建一个新事件。
- 当我还尝试获取 Google Meet 链接时,我收到错误消息:“会议类型值无效”
这是我的代码:
$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));
如果没有参数“array('conferenceDataVersion' => 1)”,则正在创建事件。我几乎可以肯定它与访问权限有关,但我不知道再去哪里看......