【发布时间】:2021-09-27 02:10:36
【问题描述】:
我正在使用 PHP 通过 Google Calendar API 在 Google Calendar 上创建一个活动,我可以在创建活动时自动创建 Meet 链接,但我想在创建活动时添加现有的 Meet 链接,但它不起作用。我尝试使用Google_Service_Calendar_Event::setHangoutLink() 来设置特定的Google Meet URL,但当我调用Google_Service_Calendar_Event::insert() 时不会受到影响
这是我的代码:
$client = $this->getClient();
$service = new \Google_Service_Calendar($client);
$calendarId = $this->calendarId;
$startTime = date(DATE_ATOM, $startTime);
$endTime = date(DATE_ATOM, $endTime);
$event = new \Google_Service_Calendar_Event();
$event->setSummary($title);
$startObj = new \Google_Service_Calendar_EventDateTime();
$startObj->setDateTime($startTime);
$startObj->setTimeZone('Asia/Ho_Chi_Minh');
$event->setStart($startObj);
$endObj = new \Google_Service_Calendar_EventDateTime();
$endObj->setDateTime($endTime);
$endObj->setTimeZone('Asia/Ho_Chi_Minh');
$event->setEnd($endObj);
$conferenceObj = new \Google_Service_Calendar_ConferenceData();
$entryPointObj = new Google_Service_Calendar_EntryPoint();
$entryPointObj->setAccessCode('<access code goes here>');
$entryPointObj->setMeetingCode('<meeting code goes here>');
$conferenceObj->setEntryPoints($entryPointObj);
$conferenceSolutionObj = new \Google_Service_Calendar_ConferenceSolution();
$conferenceSolutionObj->setIconUri(null);
$conferenceSolutionObj->setKey(new \Google_Service_Calendar_ConferenceSolutionKey());
$conferenceObj->setConferenceSolution($conferenceSolutionObj);
$conferenceRequestObj = new \Google_Service_Calendar_CreateConferenceRequest();
$requestId = strtolower(preg_replace('/\-?\s?\_?/', '', $title));
$conferenceRequestObj->setRequestId($requestId);
$conferenceSolutionKeyObj = new \Google_Service_Calendar_ConferenceSolutionKey();
$conferenceSolutionKeyObj->setType("hangoutsMeet");
$conferenceRequestObj->setConferenceSolutionKey($conferenceSolutionKeyObj);
$conferenceRequestObj->setStatus(new \Google_Service_Calendar_ConferenceRequestStatus());
$conferenceObj->setCreateRequest($conferenceRequestObj);
$event->setConferenceData($conferenceObj);
$event->setHangoutLink('<my google meet link...>');
$optionalConference = array('conferenceDataVersion' => 1);
$created_event = $service->events->insert($calendarId, $event,$optionalConference);
print_r($created_event);
【问题讨论】:
-
您在运行此代码时是否遇到任何错误?
-
不,不是,事件可以创建成功但不设置具体链接,只是api响应的链接
-
您能否确认您通过了准确的会议代码?
-
@ale13 是的,我很确定。会议代码字符串的格式是什么?它们是否在代码中每 3 个字符后包含“-”?例如
abc-def-ghi或ABCDEFGHI。 -
我很抱歉造成混乱,但您想要的无法实现。请检查我在下面提供的答案。
标签: php google-calendar-api google-meet