简体   繁体   中英

Google Calendar API stopped sending invitation to attendees and does not show on calendar

Google Calendar PHP client used to Create/Manage Calendar events with the help of Service Account.

Suddenly It stopped working, Events are getting created but attendees not getting any invite or event is not reflecting on the Calendar.

These events are visible those through event.list with status confirmed.

We have tried give different permission from admin console as well as sharing calendar with service account email but did not work.

$clientId = '<CLIENT_ID>'
$serviceAccountName = '<SERVICE_ACCOUNT_NAME>';
$Key = file_get_contents( 'Path_to_api_key_file.p12' );

$GoogleClient = new Google_Client();
$GoogleClient->setClientId( $clientId );
$GoogleClient->setUseObjects( true );

$GoogleClient->setAssertionCredentials( new Google_AssertionCredentials( $serviceAccountName, array( 'https://www.googleapis.com/auth/calendar' ), $Key ) );

$GoogleCalendarService = new Google_CalendarService( $GoogleClient );

$StartDateTime  = new DateTime( getScheduledStartTime() );
$EndDateTime    = new DateTime( getScheduledEndTime() );

$GoogleEvent = new Google_Event();

$GoogleEvent->setSummary( 'Calendar Session for test' );
$GoogleEvent->setDescription( 'Reproduce Issue' );

$StartGoogleEventDateTime = new Google_EventDateTime();
$StartGoogleEventDateTime->setTimeZone( date_default_timezone_get() );
$StartGoogleEventDateTime->setDateTime( $StartDateTime->format( 'Y-m-d\TH:i:s' ) );

$GoogleEvent->setStart( $StartGoogleEventDateTime );

$EndGoogleEventDateTime = new Google_EventDateTime();
$EndGoogleEventDateTime->setTimeZone( date_default_timezone_get() );
$EndGoogleEventDateTime->setDateTime( $EndDateTime->format( 'Y-m-d\TH:i:s' ) );

$GoogleEvent->setEnd( $EndGoogleEventDateTime );

$EventCreator = new Google_EventCreator();
$EventCreator->setDisplayName( 'Training Team' );
$EventCreator->setEmail( '<TrainingEmail@tld>' );

$GoogleEvent->setCreator( $EventCreator );

$EventAttendee = new Google_EventAttendee();
$EventAttendee->setEmail( '<TrainingEmail@tld>' );
$EventAttendee->setOrganizer( true );
$GoogleEvent->attendees[] = $EventAttendee;

$EventAttendee1 = new Google_EventAttendee();
$EventAttendee1->setEmail( '<attendees@emailaddress>' );
$GoogleEvent->attendees[] = $EventAttendee1;

$GoogleEvent->setVisibility( 'default' );
$GoogleEvent->setKind( 'calendar#calendar' );

$objCalendarEventDetails = $GoogleCalendarService->events->insert( $serviceAccountName , $GoogleEvent, array( 'sendNotifications' => true ) );

What steps will reproduce the problem?

 1. Setup a Service account and create key.
 2. create PHP script to add calendar events as like the above one
 3. Run the script and check whether event is getting added or not.

It is expected that attendees should receive an event notification via email and should be able to see the event on their calendar.

This is the workaround that we implemented to resolve the issue.

When using service accounts, we tried to impersonate a real user account when creating events (rather than using as event organizer the service account itself.).

$clientId = '<CLIENT_ID>'
$serviceAccountName = '<SERVICE_ACCOUNT_NAME>';
$Key = file_get_contents( 'Path_to_api_key_file.p12' );

$GoogleClient = new Google_Client();
$GoogleClient->setClientId( $clientId );
$GoogleClient->setUseObjects( true );

$GoogleClient->setAssertionCredentials( new Google_AssertionCredentials( $serviceAccountName, array( 'https://www.googleapis.com/auth/calendar' ), $Key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', '<IMPERSONATE_USER_ID>') );

$GoogleCalendarService = new Google_CalendarService( $GoogleClient );

$StartDateTime  = new DateTime( getScheduledStartTime() );
$EndDateTime    = new DateTime( getScheduledEndTime() );

$GoogleEvent = new Google_Event();

$GoogleEvent->setSummary( 'Calendar Session for test' );
$GoogleEvent->setDescription( 'Reproduce Issue' );

$StartGoogleEventDateTime = new Google_EventDateTime();
$StartGoogleEventDateTime->setTimeZone( date_default_timezone_get() );
$StartGoogleEventDateTime->setDateTime( $StartDateTime->format( 'Y-m-d\TH:i:s' ) );

$GoogleEvent->setStart( $StartGoogleEventDateTime );

$EndGoogleEventDateTime = new Google_EventDateTime();
$EndGoogleEventDateTime->setTimeZone( date_default_timezone_get() );
$EndGoogleEventDateTime->setDateTime( $EndDateTime->format( 'Y-m-d\TH:i:s' ) );

$GoogleEvent->setEnd( $EndGoogleEventDateTime );

$EventCreator = new Google_EventCreator();
$EventCreator->setDisplayName( 'Training Team' );
$EventCreator->setEmail( '<IMPERSONATE_USER_ID>' );

$GoogleEvent->setCreator( $EventCreator );

$EventAttendee = new Google_EventAttendee();
$EventAttendee->setEmail( '<TrainingEmail@tld>' );
$EventAttendee->setOrganizer( true );
$GoogleEvent->attendees[] = $EventAttendee;

$EventAttendee1 = new Google_EventAttendee();
$EventAttendee1->setEmail( '<attendees@emailaddress>' );
$GoogleEvent->attendees[] = $EventAttendee1;

$GoogleEvent->setVisibility( 'default' );
$GoogleEvent->setKind( 'calendar#calendar' );

$objCalendarEventDetails = $GoogleCalendarService->events->insert( '<IMPERSONATE_USER_ID>', $GoogleEvent, array( 'sendNotifications' => true ) );

Note: Impersonate account that we used here is the same account that used to create the service account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM