Добавление событий в Календарь Google от разных пользователей - PullRequest
0 голосов
/ 21 мая 2019

Я хочу настроить систему бронирования на моем веб-сайте, я пробовал код ниже, но он добавляет событие в календарь Google пользователя, но я хочу добавить события только в свой личный календарь, как я могу сделать это?

<?php
require_once __DIR__.'/vendor/autoload.php';
session_start();
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php');
$client->setAccessType('offline');        // offline access
$client->setIncludeGrantedScopes(true);   // incremental auth



if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    $client->setAccessToken($_SESSION['access_token']);

    $calendarId = 'primary';
    $service = new Google_Service_Calendar($client);



    $event = new Google_Service_Calendar_Event(array(
      'summary' => 'Titre de l\'evennement',
      'location' => 'Le lieu',
      'description' => 'La description',
      'start' => array(
        'dateTime' => '2019-05-28T09:00:00-07:00',
        'timeZone' => 'America/Los_Angeles',
      ),
      'end' => array(
        'dateTime' => '2019-05-28T17:00:00-07:00',
        'timeZone' => 'America/Los_Angeles',
      ),
      'recurrence' => array(
        'RRULE:FREQ=DAILY;COUNT=2'
      ),
      'attendees' => array(
        array('email' => 'lpage@example.com'),
        array('email' => 'sbrin@example.com'),
      ),
      'reminders' => array(
        'useDefault' => FALSE,
        'overrides' => array(
          array('method' => 'email', 'minutes' => 24 * 60),
          array('method' => 'popup', 'minutes' => 10),
        ),
      ),
    ));

    $event = $service->events->insert($calendarId, $event);
    printf('Event created: %s\n', $event->htmlLink);


} else {
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
...