Kareem Saeed
Kareem Saeed

Reputation: 75

View meet link to each event created in a google calendar

In a laravel 5.8 project user can create new events using my app and then save those events to his google calendar via OAUTH 2 so that he can view, edit or even delete them. new conference data will be added automatically with each created event. I want to view google meet link with each event created so that guests can click this link to attend the conference

I started by adding event data and creating new conference data and adding its entry point and using Google_Service_Calendar_ConferenceSolutionKey class to determine its type which is "hangoutsMeet" and finally I added conference data to the event

Here is the function I am using to create new events:

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 Event created successfully but no conference data showed on user's google calendar event card so he can not access the new created conference meet link

The question is how can I know if conference data is added to the event successfully although hangout meet link did not show on the event card?

Upvotes: 2

Views: 4987

Answers (3)

tiu
tiu

Reputation: 131

This combination of the answers above worked for me:

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

Upvotes: 8

user3131314
user3131314

Reputation: 1

 $created_event = $cal->events->insert(
    $calendar_id, 
    $event, 
    ['conferenceDataVersion' => 1]
);

Need to set the conferenceDataVersion => 1 as one in the optional parameter set.

Upvotes: 0

Jessica Rodriguez
Jessica Rodriguez

Reputation: 2974

There's no information regarding how to show the meet link in calendar event card from the documentation. You will need to manually insert/input from the comment section the url of Hangout meeting. I would like to suggest to use the Events formats from Hangouts Chat API.

Upvotes: 0

Related Questions