首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google日历API-创建活动时不向参与者发送邀请电子邮件

Google日历API-创建活动时不向参与者发送邀请电子邮件
EN

Stack Overflow用户
提问于 2013-10-03 20:14:30
回答 2查看 5.4K关注 0票数 3

我想添加事件到谷歌日历使用谷歌api。但在创建活动后,邀请电子邮件不会发送到与会者的电子邮件列表。下面是我的代码:

代码语言:javascript
复制
 <?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创建活动后,我如何向与会者列表发送电子邮件?谢谢。

EN

回答 2

Stack Overflow用户

发布于 2013-10-15 16:24:08

insert方法有一个可选参数:

代码语言:javascript
复制
    /**
 * 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
 */

所以我是这样解决的:

代码语言:javascript
复制
[... ]$event->attendees = $attendees;

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

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

票数 8
EN

Stack Overflow用户

发布于 2019-10-25 04:16:57

在较新的API版本中,需要添加一个名为sendUpdates="all"的参数

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

所以就像这样:

代码语言:javascript
复制
$optionalArguments = array("sendUpdates"=>"all");
$createdEvent = $cal->events->insert($idCalendar, $event, $optionalArguments);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19158964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档