【问题标题】:Google Calendar PHP API Not Sending Invite Emails谷歌日历 PHP API 不发送邀请电子邮件
【发布时间】:2026-02-02 17:45:01
【问题描述】:

我已使用 PHP 和服务帐户成功地与 Google 日历集成。

我能做什么:

  • 更新日历事件。
  • 将参与者添加到日历活动中。

我不能做什么:

  • 添加新与会者时发送邀请电子邮件。

这是我目前用来完成所有工作的全部代码:

putenv('GOOGLE_APPLICATION_CREDENTIALS=credentials.json');

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes('https://www.googleapis.com/auth/calendar');
$client->setSubject('example@gmail.com');

$service = new Google_Service_Calendar($client);

$calendarID = 'primary';
$eventID = 'XXXXXXXXX';
$event = new Google_Service_Calendar_Event(array(
    'sendNotifications' => true,
    'attendees' => array(
        array('email' => 'email1@gmail.com)
    )
));

$event = $service->events->patch($calendarID, $eventID, $event);

【问题讨论】:

标签: php google-calendar-api


【解决方案1】:

聚会迟到了,但因为没有答案......

我刚刚遇到了同样的问题。几件事:

  • sendNotifications 已弃用,您应该改用 sendUpdates
  • 可选参数不会在事件本身中进行 - 它们会出现在请求中。所以你最终得到:
$event = $service->events->patch(
    $calendarID, 
    $eventID, 
    $event, 
    ['sendUpdates' => 'all']
);

【讨论】:

  • 这对我也有用!谢谢。我很困惑他们没有在文档中提到它:(
  • 虽然 sendNotifications 已被弃用,但它似乎仍然是在附加组件中使用带有 appscript 的高级日历服务时唯一有效的方法。任何人都可以对此有所了解吗?