Google Calendar API-创建活动时,邀请电子邮件不会发送给与会者 [英] Google calendar API- Invitation email doesn't send to attendees when create event

查看:67
本文介绍了Google Calendar API-创建活动时,邀请电子邮件不会发送给与会者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google API将事件添加到Google日历. 但是在创建事件后,邀请电子邮件不会发送到与会者电子邮件列表. 这是我的代码:

I want to add event to google calendar using google api. But after event created, invitation email doesn't send to attendees email list. Here is my code:

 <?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***.ictu@gmail.com");
    $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创建事件后如何发送电子邮件到与会者列表? 谢谢.

So my question is how can i send email to attendees list after event created from API? Thank you.

推荐答案

insert方法具有可选参数:

the insert method has an optional parameter:

    /**
 * 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
 */

所以我以这种方式解决:

So I resolve in this way:

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

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

现在,与会者会收到一封带有.ics文件的电子邮件,就像来自Google日历的普通邀请一样

Now the attendees receive an email with a .ics file like a normal invitation from Google Calendar

这篇关于Google Calendar API-创建活动时,邀请电子邮件不会发送给与会者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆