Google Calendar PHP API Not Sending Invite Emails

2019-07-16 02:38发布

I have successfully integrated with Google Calendar using PHP with a Service Account.

What I can do:

  • Update the calendar event.
  • Add attendees to the calendar event.

What I can not do:

  • Send invite emails when new attendees are added.

Here is the entire code that I use to accomplish everything so far:

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);

1条回答
别忘想泡老子
2楼-- · 2019-07-16 03:01

Late to the party but since there are no answers...

I've just been having this exact same problem. Few things:

  • sendNotifications is deprecated, you should be using sendUpdates instead.
  • The optional Params don't go on the event itself - they go in the request. So you end up with:

$event = $service->events->patch( $calendarID, $eventID, $event, ['sendUpdates' => 'all'] );

查看更多
登录 后发表回答