Php 查看谷歌日历中创建的每个活动的会议链接

Php 查看谷歌日历中创建的每个活动的会议链接,php,google-calendar-api,Php,Google Calendar Api,在laravel 5.8项目中,用户可以使用我的应用程序创建新事件,然后通过OAUTH 2将这些事件保存到他的谷歌日历中,以便查看、编辑甚至删除它们。新的会议数据将随每个创建的事件自动添加。 我想查看创建的每个活动的google meet链接,以便来宾可以单击此链接参加会议 我开始添加事件数据,创建新的会议数据,添加其入口点,并使用Google_服务_日历_ConferenceSolutionKey类确定其类型,即“hangoutsMeet”,最后我将会议数据添加到事件中 以下是我用来创建新事件

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

我开始添加事件数据,创建新的会议数据,添加其入口点,并使用Google_服务_日历_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!'
                ]);
  }
事件创建成功,但用户的google日历事件卡上没有显示会议数据,因此他无法访问新创建的会议链接


问题是,尽管活动卡上没有显示“聚会”链接,我如何知道会议数据是否已成功添加到活动中?

没有关于如何在日历活动卡中显示“聚会”链接的信息。您需要从评论部分手动插入/输入挂断会议的url。 我建议您使用from Hangouts聊天API。

$created\u event=$cal->events->insert(
$calendar\u id,
$event,
['conferenceDataVersion'=>1]
);

需要将
conferenceDataVersion=>1
设置为可选参数集中的一个

以上这些答案的组合对我很有用:

$event=new\Google\u服务\u日历\u事件(数组)(
“摘要”=>“约会”,
“位置”=>“地球”,
'description'=>'Hello world',
“开始”=>数组(
'dateTime'=>Carbon::now()->格式('c'),
“时区”=>“欧洲/苏黎世”,
),
'结束'=>数组(
'dateTime'=>Carbon::now()->addMinutes(15)->format('c'),
“时区”=>“欧洲/苏黎世”,
)
));
$calendarId='primary';
$event=$service->events->insert($calendarId,$event);
printf('创建的事件:%s',$Event->htmlink);
$conference=new\Google\u Service\u Calendar\u ConferenceData();
$conferenceRequest=new\Google_服务_日历_CreateConferenceRequest();
$conferenceRequest->setRequestId('randomString123');
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
$event=$service->events->patch($calendarId,$event->id,$event,['conferenceDataVersion'=>1]);
printf(“
创建的会议:%s”,$event->hangoutLink);
默认情况下,当会议数据成功添加到活动中时,hangout meet链接将出现在活动卡中