首页 > 解决方案 > 如何在 Google 日历活动中更新与会者列表?

问题描述

下面的代码用于更新标题、详细信息和位置:

$event->setSummary($_POST['title']);
$event->setDescription($_POST['detail']);
$event->setLocation($_POST['location']);

下面的代码是更新日期(开始和结束):

$start = new Google_Service_Calendar_EventDateTime();
$start->setTimeZone($timezone);
$start->setDateTime($startDateTime);
$event->setStart($start);

$end = new Google_Service_Calendar_EventDateTime();
$end->setTimeZone($timezone);
$end->setDateTime($endDateTime);
$event->setEnd($end);

但我正在努力更新与会者名单。对于插入一个如下:

$people = $_POST['people'];  // POST from other webpage
$finalpeople = [];
foreach ($people as $person) {
    $finalpeople[] = ['email' => $person];
}
$data['result'] = $finalpeople;

// just look at the attendees one
$event = new Google_Service_Calendar_Event(array(
    'id'=>  $idFinal,
    'summary' => $_POST['title'],
    'location' => $_POST['location'],
    'description' => $_POST['detail'],
    'start' => array(
      'dateTime' => $startDateTime,
      'timeZone' => $_POST['timezone'],
    ),
    'end' => array(
      'dateTime' => $endDateTime,
      'timeZone' =>  $_POST['timezone'],
    ),
    'attendees' => $data['result'],
    'reminders' => array(
      'useDefault' => FALSE,
      'overrides' => array(
        array('method' => 'email', 'minutes' => 24 * 60),
        array('method' => 'popup', 'minutes' => $_POST['reminder']),
      ),
    ),
  ));

任何人有任何想法更新与会者?

标签: phpapieventscalendar

解决方案


我相信你的目标如下。

  • 您想要使用 googleapis 和 PHP 更新活动中的参与者。
  • 您已经能够使用 Calendar API 获取和放置 Google Calendar 的值。

为此,这个答案怎么样?在这种情况下,我建议在 Calendar API 中使用 Events: patch 的方法。

示例脚本:

$client = getClient();
$calendar = new Google_Service_Calendar($client);

$calendarId = "###";  // Please set the calendar ID.
$eventId = "###";  // Please set the event ID.

// Here, please set the new attendees.
$newAttendees = [
    array(
        'email' => '###',
        'comment' => 'sample 1'
    ),
    array(
        'email' => '###',
        'comment' => 'sample 2'
    )
];

$event = new Google_Service_Calendar_Event;
$event->attendees = $newAttendees;
$result = $calendar->events->patch($calendarId, $eventId, $event);

笔记:

  • 当您使用$newAttendees时,现有活动的参加者将被覆盖。所以请注意这一点。所以我建议使用示例事件来测试上述脚本。

参考:


推荐阅读