gpt4 book ai didi

php - 查看在谷歌日历中创建的每个事件的 session 链接

转载 作者:行者123 更新时间:2023-12-05 09:13:11 25 4
gpt4 key购买 nike

在 laravel 5.8 项目中,用户可以使用我的应用程序创建新事件,然后通过 OAUTH 2 将这些事件保存到他的谷歌日历中,以便他可以查看、编辑甚至删除它们。每个创建的事件都会自动添加新的 session 数据。我想查看创建的每个事件的 google meet 链接,以便客人可以单击此链接参加 session

我首先添加事件数据并创建新的 session 数据并添加其入口点并使用 Google_Service_Calendar_ConferenceSolutionKey 类确定其类型为“hangoutsMeet”,最后我将 session 数据添加到事件中

这是我用来创建新事件的函数:

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!'
]);
}

Event Card事件创建成功,但用户的谷歌日历事件卡片上没有显示 session 数据,因此他无法访问新创建的 session 链接

问题是,虽然环聊 session 链接没有显示在事件卡片上,但我如何知道 session 数据是否已成功添加到事件中?

最佳答案

上述答案的组合对我有用:

$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);

关于php - 查看在谷歌日历中创建的每个事件的 session 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56619943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com