API календаря Google: электронное письмо с приглашением не отправляется участникам при создании мероприятия

Я хочу добавить событие в календарь Google с помощью API Google. Но после создания мероприятия электронное письмо с приглашением не отправляется в список рассылки участников. Вот мой код:

 <?php
    require_once '../../src/Google_Client.php';
    require_once '../../src/contrib/Google_CalendarService.php';
    session_start();

    $client = new Google_Client();
    $client->setApplicationName("Google Calendar PHP Starter Application");

    // Visit https://code.google.com/apis/console?api=calendar to generate your
    // client id, client secret, and to register your redirect uri.
     $client->setClientId('309388785502.apps.googleusercontent.com');
     $client->setClientSecret('hvJQUDYz4rY0HiYcgS46yxB-');
     $client->setRedirectUri('http://localhost/GoogleApi/google-api-php-client/examples/calendar/simple.php');
     $client->setDeveloperKey('AIzaSyAbBRxRKM9mkXKA17Bruul6lCq-vhR6gqc');
    $cal = new Google_CalendarService($client);
    if (isset($_GET['logout'])) {
      unset($_SESSION['token']);
    }

    if (isset($_GET['code'])) {
      $client->authenticate($_GET['code']);
      $_SESSION['token'] = $client->getAccessToken();
      header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }

    if (isset($_SESSION['token'])) {
      $client->setAccessToken($_SESSION['token']);
    }

    if ($client->getAccessToken()) {

     $event = new Google_Event();
      $event->setSummary('Halloween3');
      $event->setLocation('The Neighbourhood');
      $start = new Google_EventDateTime();
      $start->setDate('2013-10-3');
      $event->setStart($start);
      $end = new Google_EventDateTime();
      $end->setDate('2013-10-3');
      $event->setEnd($end);
      $event->sendNotifications=true;
      $event->maxAttendees=2;
      $attendee1 = new Google_EventAttendee();
      $attendee2 = new Google_EventAttendee();
    $attendee1->setEmail("cuong***[email protected]");
    $attendee2->setEmail("webtr***@gmail.com");
    $attendees = array($attendee1,$attendee2);
    $event->attendees = $attendees;

      $createdEvent = $cal->events->insert('primary', $event);

    $_SESSION['token'] = $client->getAccessToken();
    } else {
      $authUrl = $client->createAuthUrl();
      print "<a class='login' href='$authUrl'>Connect Me!</a>";
    }

?>

Итак, мой вопрос: как я могу отправить электронное письмо в список участников после события, созданного из API? Спасибо.


person Cuong Nguyen    schedule 03.10.2013    source источник


Ответы (2)


метод вставки имеет необязательный параметр:

    /**
 * Creates an event. (events.insert)
 *
 * @param string $calendarId Calendar identifier.
 * @param Google_Event $postBody
 * @param array $optParams Optional parameters.
 *
 * @opt_param int maxAttendees The maximum number of attendees to include in the response. If there are more than the specified number of attendees, only the participant is returned. Optional.
 * @opt_param bool sendNotifications Whether to send notifications about the creation of the new event. Optional. The default is False.
 * @return Google_Event
 */

Итак, я решаю таким образом:

[... ]$event->attendees = $attendees;

$optionaArguments = array("sendNotifications"=>true);
$createdEvent = $cal->events->insert($idCalendario, $event, $optionaArguments);
[...]

Теперь участники получают электронное письмо с файлом .ics, как обычное приглашение из Календаря Google.

person Chiara Gandolfi    schedule 15.10.2013
comment
Обратите внимание, что теперь это было заменено на sendUpdates, а sendNotifications устарел: developers.google .com/calendar/v3/reference/events/insert - person Apollo Data; 24.10.2019

В более новой версии API вы добавляете параметр с именем sendUpdates="all":

https://developers.google.com/calendar/v3/reference/events/insert

Итак, что-то вроде:

$optionalArguments = array("sendUpdates"=>"all");
$createdEvent = $cal->events->insert($idCalendar, $event, $optionalArguments);
person Apollo Data    schedule 24.10.2019