查看 Google 日历中创建的每个活动的会议链接
Posted
技术标签:
【中文标题】查看 Google 日历中创建的每个活动的会议链接【英文标题】:View meet link to each event created in a google calendar 【发布时间】:2019-10-30 09:01:57 【问题描述】:在 laravel 5.8 项目中,用户可以使用我的应用程序创建新事件,然后通过 OAUTH 2 将这些事件保存到他的谷歌日历,以便他可以查看、编辑甚至删除它们。每个创建的事件都会自动添加新的会议数据。 我想查看创建的每个活动的 google meet 链接,以便客人可以单击此链接参加会议
我首先添加事件数据并创建新的会议数据并添加其入口点并使用 Google_Service_Calendar_ConferenceSolutionKey 类来确定其类型为“hangoutsMeet”,最后我将会议数据添加到事件中
这是我用来创建新事件的函数:
public function doCreateEvent(Event $evt, Request $request)
$this->validate($request, [
'title' => 'required',
'calendar_id' => 'required',
'datetime_start' => 'required|date',
'datetime_end' => 'required|date'
]);
$title = $request->input('title');
$calendar_id = $request->input('calendar_id');
$start = $request->input('datetime_start');
$end = $request->input('datetime_end');
$start_datetime = Carbon::createFromFormat('Y/m/d H:i', $start);
$end_datetime = Carbon::createFromFormat('Y/m/d H:i', $end);
$cal = new \Google_Service_Calendar($this->client);
$event = new \Google_Service_Calendar_Event();
$event->setSummary($title);
$start = new \Google_Service_Calendar_EventDateTime();
$start->setDateTime($start_datetime->toAtomString());
$event->setStart($start);
$end = new \Google_Service_Calendar_EventDateTime();
$end->setDateTime($end_datetime->toAtomString());
$event->setEnd($end);
// Create new conference
$conference = new \Google_Service_Calendar_ConferenceData();
$entryPoint = new \Google_Service_Calendar_EntryPoint();
$entryPoint->setAccessCode('wx12z3s');
$entryPoint->setEntryPointType('video');
$entryPoint->setLabel('meet.google.com/wx12z3s');
$entryPoint->setMeetingCode('wx12z3s');
$entryPoint->setPasscode('wx12z3s');
$entryPoint->setPassword('wx12z3s');
$entryPoint->setPin('wx12z3s');
$entryPoint->setUri('https://meet.google.com/wx12z3s');
$conference->setEntryPoints($entryPoint);
$conferenceSolution = new \Google_Service_Calendar_ConferenceSolution();
$conferenceSolution->setIconUri(null);
$conferenceSolution->setKey(new \Google_Service_Calendar_ConferenceSolutionKey());
$conference->setConferenceSolution($conferenceSolution);
$conferenceRequest = new \Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId($request->_token);
$conferenceSolutionKey = new \Google_Service_Calendar_ConferenceSolutionKey();
$conferenceSolutionKey->setType("hangoutsMeet");
$conferenceRequest->setConferenceSolutionKey($conferenceSolutionKey);
$conferenceRequest->setStatus(new \Google_Service_Calendar_ConferenceRequestStatus());
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
//attendee
if ($request->has('attendee_name'))
$attendees = [];
$attendee_names = $request->input('attendee_name');
$attendee_emails = $request->input('attendee_email');
foreach ($attendee_names as $index => $attendee_name)
$attendee_email = $attendee_emails[$index];
if (!empty($attendee_name) && !empty($attendee_email))
$attendee = new \Google_Service_Calendar_EventAttendee();
$attendee->setEmail($attendee_email);
$attendee->setDisplayName($attendee_name);
$attendees[] = $attendee;
$event->attendees = $attendees;
$created_event = $cal->events->insert($calendar_id, $event);
$evt->title = $title;
$evt->calendar_id = $calendar_id;
$evt->event_id = $created_event->id;
$evt->datetime_start = $start_datetime->toDateTimeString();
$evt->datetime_end = $end_datetime->toDateTimeString();
$evt->save();
return redirect('/event/create')
->with('message', [
'type' => 'success',
'text' => 'Event was created!'
]);
活动创建成功,但用户的谷歌日历活动卡上没有显示会议数据,因此他无法访问新创建的会议会议链接
问题是,虽然活动卡片上没有显示环聊聚会链接,但我如何知道会议数据是否已成功添加到活动中?
【问题讨论】:
【参考方案1】:以上答案的组合对我有用:
$event = new \Google_Service_Calendar_Event(array(
'summary' => 'Appointment',
'location' => 'Earth',
'description' => 'Hello world',
'start' => array(
'dateTime' => Carbon::now()->format('c'),
'timeZone' => 'Europe/Zurich',
),
'end' => array(
'dateTime' => Carbon::now()->addMinutes(15)->format('c'),
'timeZone' => 'Europe/Zurich',
)
));
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s', $event->htmlLink);
$conference = new \Google_Service_Calendar_ConferenceData();
$conferenceRequest = new \Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId('randomString123');
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
$event = $service->events->patch($calendarId, $event->id, $event, ['conferenceDataVersion' => 1]);
printf('<br>Conference created: %s', $event->hangoutLink);
【讨论】:
【参考方案2】:documentation 没有关于如何在日历活动卡片中显示会议链接的信息。您需要从评论部分手动插入/输入环聊会议的网址。 我想建议使用环聊聊天 API 中的 Events formats。
【讨论】:
默认情况下,当会议数据成功添加到活动时,视频群聊链接会出现在活动卡片中【参考方案3】: $created_event = $cal->events->insert(
$calendar_id,
$event,
['conferenceDataVersion' => 1]
);
需要在可选参数集中将conferenceDataVersion => 1
设置为1。
【讨论】:
以上是关于查看 Google 日历中创建的每个活动的会议链接的主要内容,如果未能解决你的问题,请参考以下文章
我如何测试标记为“自动拒绝新的和现有的会议”的Google日历活动]]
与会者在使用服务帐户、谷歌日历 API 创建活动时未收到会议邀请