开发者控制台中创建了一个服务帐号,并在具有管理员权限的 Google 日历中添加了服务帐号电子邮件 ID。
这里的问题是事件邀请和提醒不会通过服务帐户自动触发,但使用客户端 ID 和密钥可以发送邀请和提醒的电子邮件。
使用oauth2.0 会提示用户登录并允许访问,但在这里,需要访问自己的 Google 日历,因此,使用服务帐户创建事件,但不发送邀请和提醒。
参考:使用 oauth2.0 和服务帐户的 Google 事件插入 V3
是否有任何解决方法或解决问题,请帮助我们。提前谢谢。
下面是事件创建对象。
$event = new Google_Service_Calendar_Event(
array(
'summary' => $title,
'start' => array(
'dateTime' => $data['start_date_time'],
),
'end' => array(
'dateTime' => $data['end_date_time'],
),
'attendees' => array(
array(
'email' => $data['student_email'],
'displayName' => $data['student_name'],
'responseStatus' => "needsAction"
),
array(
'email' => $data['mentor_email'],
'displayName' => $data['mentor_name'],
'responseStatus' => "needsAction"
),
),
'guestsCanInviteOthers' => false,
'guestsCanSeeOtherGuests' => false,
'sendUpdates' => "all",
)
$service = new Google_Service_Calendar($this->client);
$event = $service->events->insert($this->calendar_id, $event);
参考:使用 oauth2.0 和服务帐户插入 Google 事件插入 V3
请求有请求正文和请求参数。sendUpdates 是请求正文中使用的请求参数,因此不会发送通知和邀请。
使用以下代码:从事件请求正文中删除属性 sendUpdates(如果有)。
$service = new Google_Service_Calendar($this->client);
$event = $service->events->insert($this->calendar_id, $event, array('sendUpdates' => 'all'));
请求正文与上述相同。
谢谢。