You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Calendar API PHP创建/修改事件sendUpdates参数不生效求助

解决方案

核心问题是sendUpdates参数的配置位置错误:该参数属于API请求的全局控制参数,不是日历事件本身的属性,不能写入Google_Service_Calendar_Event的构造参数中,写在该位置的参数会被API直接忽略。

正确的插入(insert)写法

移除$opts里的sendUpdates参数,放到insert方法的第三个可选参数数组中即可实现创建事件时自动给所有参会人发通知,无需额外调用patch,示例代码:

$opts = [ 
  'start' => [
    'date' => '2021-10-11',
    'timeZone' => 'US/Pacific'
  ],  
  'end' => [
    'date' => '2021-10-11',
    'timeZone' => 'US/Pacific'
  ],  
  'summary' => 'TEST EVENT',
  'description' => 'Test description',
  'attendees' => [['email'=>'test@test.com']],  
  'guestsCanModify' => false,
  'guestsCanInviteOthers' => true,
  'guestsCanSeeOtherGuests' => true,
  'reminders' => [
    'useDefault' => true,
  ]
];
$event = new \Google_Service_Calendar_Event($opts);
// sendUpdates作为第三个请求参数传入
$new_event = $service->events->insert($calendar_id, $event, ['sendUpdates' => 'all']);

patch更新的注意事项

你写的patch方法参数位置是正确的,但要满足两个条件才会触发通知:

  • 仅当传入的事件对象有实际字段变更时,API才会发送通知,如果没有任何内容修改,即使传了sendUpdates参数也不会触发通知
  • 不要直接把insert返回的完整事件对象传入patch方法,建议只构造需要修改的字段的事件对象,避免不必要的字段覆盖,示例:
// 仅构造需要修改的字段
$updatedEvent = new \Google_Service_Calendar_Event([
  'summary' => '修改后的事件标题'
]);
$service->events->patch($calendar_id, $eventId, $updatedEvent, ['sendUpdates' => 'all']);

额外排查点

如果修改参数后依然不生效,可以排查以下配置:

  • 确认你的API授权凭证对目标日历有编辑及以上权限
  • 确认参会人邮箱地址有效,且未设置谷歌日历通知拦截规则
  • 如果你使用服务账号调用,确认已经开启全域权限委托,且模拟了真实的日历所属用户操作,避免服务账号直接创建的事件通知被邮箱服务商拦截

内容的提问来源于stack exchange,提问作者RJW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 06:18:04