Google Calendar API停止向与会者发送邀请,并且不在日历上显示

问题描述 投票:1回答:1

Google Calendar PHP客户端,用于在服务帐户的帮助下创建/管理日历事件。

突然停止工作,创建了活动,但与会者没有收到任何邀请,或者活动未反映在日历上。

这些事件通过event.list可见,状态已确认。

我们已尝试从管理控制台中授予不同的权限,以及与服务帐户电子邮件共享日历,但无效。

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

哪些步骤将重现问题?

 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.

预计与会者应该通过电子邮件收到事件通知,并且应该能够在其日历上看到该事件。

php google-calendar-api service-accounts
1个回答
0
投票

这是我们为解决此问题而实施的解决方法。

[使用服务帐户时,我们试图在创建事件时模拟真实的用户帐户(而不是使用服务帐户本身作为事件组织者。)

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

注意:我们在这里使用的模拟帐户与用于创建服务帐户的帐户相同。

© www.soinside.com 2019 - 2024. All rights reserved.