Я борюсь с API доступа и управления (CRUD) ко всем календарям пользователей, которые принадлежат моей учетной записи GSuite.
Я хочу просто получить доступ к данным пользователей без необходимости авторизации с их стороны.
После выполнения всех соответствующих руководств,
1) настройка сервисной учетной записи https://developers.google.com/calendar/auth
2) делегирование полномочий домена на учетную запись https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority
3) загрузка аутентификационных кредитов в виде файла json и вызов $this->api_client->setAuthConfig('creds.json');
Вот код:
protected $api_client;
protected $service;
public function __construct()
{
$this->api_client = new Google_Client();
$this->api_client->setApplicationName("XXXX");
$this->api_client->setScopes([
Google_Service_Directory::ADMIN_DIRECTORY_USER,
Google_Service_Directory::ADMIN_DIRECTORY_GROUP,
Google_Service_Directory::ADMIN_DIRECTORY_USER_ALIAS,
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER,
Google_Service_Calendar::CALENDAR
]);
$this->setAuthentication();
$this->service = new Google_Service_Directory($this->api_client);
}
private function setAuthentication()
{
$this->api_client->setAuthConfig('creds.json');
$this->api_client->setAccessType("offline");
}
public function createEvent()
{
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'start' => array(
'dateTime' => '2019-04-15T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2019-04-15T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => 'lpage@example.com'),
array('email' => 'sbrin@example.com'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$service = new Google_Service_Calendar($this->api_client);
$new_event = $service->events->insert('primary', $event);
return $new_event;
}
$g = new GSuiteAdmin();
$new = $g->createEvent();
echo "<pre>";
print_r($new);
Возвращаю массив без ошибок. Также вот снимок экрана метрик API Календаря Google, который, кажется, показывает, что были сделаны вызовы API без каких-либо ошибок .
Но я не могу найти событие, вставленное в календарь!
Вот вывод массива
Google_Service_Calendar_Event Object
(
[collection_key:protected] => recurrence
[anyoneCanAddSelf] =>
[attachmentsType:protected] => Google_Service_Calendar_EventAttachment
[attachmentsDataType:protected] => array
[attendeesType:protected] => Google_Service_Calendar_EventAttendee
[attendeesDataType:protected] => array
[attendeesOmitted] =>
[colorId] =>
[conferenceDataType:protected] => Google_Service_Calendar_ConferenceData
[conferenceDataDataType:protected] =>
[created] => 2019-04-15T08:49:21.000Z
[creatorType:protected] => Google_Service_Calendar_EventCreator
[creatorDataType:protected] =>
[description] => A chance to hear more about Google\'s developer products.
[endType:protected] => Google_Service_Calendar_EventDateTime
[endDataType:protected] =>
[endTimeUnspecified] =>
[etag] => "3110636323283000"
[extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties
[extendedPropertiesDataType:protected] =>
[gadgetType:protected] => Google_Service_Calendar_EventGadget
[gadgetDataType:protected] =>
[guestsCanInviteOthers] =>
[guestsCanModify] =>
[guestsCanSeeOtherGuests] =>
[hangoutLink] =>
[htmlLink] => https://www.google.com/calendar/event?eid=bW1sZWV1NTlvXXXo1NWhuMGpxaXI1NXNxazBfMjAxOTA0MTVUMTYwMDAwWiBjYWxlbmRhcmFwaUBjYWxlbmRhcmFwaS0yMzc2MTAuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20
[iCalUID] => mmleeu59osj55hn0jqir55sqk0@google.com
[id] => mmleeu59osj55hn0jqir55sqk0
[kind] => calendar#event
[location] => 800 Howard St., San Francisco, CA 94103
[locked] =>
[organizerType:protected] => Google_Service_Calendar_EventOrganizer
[organizerDataType:protected] =>
[originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime
[originalStartTimeDataType:protected] =>
[privateCopy] =>
[recurrence] => Array
(
[0] => RRULE:FREQ=DAILY;COUNT=2
)
[recurringEventId] =>
[remindersType:protected] => Google_Service_Calendar_EventReminders
[remindersDataType:protected] =>
[sequence] => 0
[sourceType:protected] => Google_Service_Calendar_EventSource
[sourceDataType:protected] =>
[startType:protected] => Google_Service_Calendar_EventDateTime
[startDataType:protected] =>
[status] => confirmed
[summary] => Google I/O 2015
[transparency] =>
[updated] => 2019-04-15T08:49:21.683Z
[visibility] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[creator] => Google_Service_Calendar_EventCreator Object
(
[displayName] =>
[email] => calendarapi@calendarapi-237610.iam.gserviceaccount.com
[id] =>
[self] => 1
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[organizer] => Google_Service_Calendar_EventOrganizer Object
(
[displayName] =>
[email] => calendarapi@calendarapi-237610.iam.gserviceaccount.com
[id] =>
[self] => 1
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[start] => Google_Service_Calendar_EventDateTime Object
(
[date] =>
[dateTime] => 2019-04-15T16:00:00Z
[timeZone] => America/Los_Angeles
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[end] => Google_Service_Calendar_EventDateTime Object
(
[date] =>
[dateTime] => 2019-04-16T00:00:00Z
[timeZone] => America/Los_Angeles
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[attendees] => Array
(
[0] => Google_Service_Calendar_EventAttendee Object
(
[additionalGuests] =>
[comment] =>
[displayName] =>
[email] => sbrin@example.com
[id] =>
[optional] =>
[organizer] =>
[resource] =>
[responseStatus] => needsAction
[self] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[1] => Google_Service_Calendar_EventAttendee Object
(
[additionalGuests] =>
[comment] =>
[displayName] =>
[email] => lpage@example.com
[id] =>
[optional] =>
[organizer] =>
[resource] =>
[responseStatus] => needsAction
[self] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
[reminders] => Google_Service_Calendar_EventReminders Object
(
[collection_key:protected] => overrides
[overridesType:protected] => Google_Service_Calendar_EventReminder
[overridesDataType:protected] => array
[useDefault] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[overrides] => Array
(
[0] => Google_Service_Calendar_EventReminder Object
(
[method] => popup
[minutes] => 10
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[1] => Google_Service_Calendar_EventReminder Object
(
[method] => email
[minutes] => 1440
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
)
)
и когда я перехожу на HTML-ссылку, она выводит меня в календарь и выдает сообщение об ошибке «Не удалось найти запрошенное событие».
ЛЮБАЯ помощь оценена !!!
Спасибо