获取 google 日历,“服务帐户无法在没有全域授权的情况下邀请与会者。”
Getting google calendar, “Service accounts cannot invite attendees without Domain-Wide Delegation of Authority.”
我可以创建活动,但是在添加与会者时 returns 这个错误
我遵循 google 指南,一切都已完成,但我无法弄清楚问题所在
我的代码
<?php
require_once(APP_LIB.'google-api/vendor/autoload.php');
$client = new Google_Client();
//The json file you got after creating the service account
putenv('GOOGLE_APPLICATION_CREDENTIALS=checkup-project-298014-b11ac6f73f7b.json');
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test_calendar");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Test Test',
'location' => 'Test Test',
'description' => 'Hello world',
'start' => array(
'dateTime' => '2020-12-18T20:00:00+01:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2020-12-18T21:20:00+01:00',
'timeZone' => 'America/Los_Angeles',
),
'attendees' => array(
array('email' => 'yasenabdelghany2222@gmail.com'),
),
));
$calendarId = 'xxxxxxxxx';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s', $event->htmlLink);
$conference = new Google_Service_Calendar_ConferenceData();
$conferenceRequest = new Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId('randomString123');
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
// ['conferenceDataVersion' => 1] is required!
$event = $service->events->patch($calendarId, $event->id, $event, ['conferenceDataVersion' => 1]);
printf('<br>Conference created: %s', $event->hangoutLink);
// printf('Event created: %s\n', $createdEvent->htmlLink);
我正在使用 google-api-php-客户端
错误:
Google\Service\Exception: { "error": { "errors": [ { "domain": "calendar", "reason": "forbiddenForServiceAccounts", "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." } ], "code": 403, "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." } } in C:\wamp\www\bbb.portal.pfhcheckups.com\app\google-api\src\Http\REST.php on line 128
Service accounts cannot invite attendees without Domain-Wide Delegation of Authority
就是这个意思。只有在 Gsuite (WorkSpace) 域上设置了域范围委托的服务帐户才能邀请人们参加活动。
请您的 Gsuite 管理员设置 domain wide delegation 服务帐户。如果您没有 gsuite 域,请获取一个或使用 Oauth2 来验证用户而不是服务帐户。
如果您已将域范围内的访问权限委派给服务帐户并且您想模拟用户帐户,请使用方法 setSubject:
指定用户帐户的电子邮件地址
$client->setSubject($user_to_impersonate);
我可以创建活动,但是在添加与会者时 returns 这个错误 我遵循 google 指南,一切都已完成,但我无法弄清楚问题所在
我的代码
<?php
require_once(APP_LIB.'google-api/vendor/autoload.php');
$client = new Google_Client();
//The json file you got after creating the service account
putenv('GOOGLE_APPLICATION_CREDENTIALS=checkup-project-298014-b11ac6f73f7b.json');
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test_calendar");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Test Test',
'location' => 'Test Test',
'description' => 'Hello world',
'start' => array(
'dateTime' => '2020-12-18T20:00:00+01:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2020-12-18T21:20:00+01:00',
'timeZone' => 'America/Los_Angeles',
),
'attendees' => array(
array('email' => 'yasenabdelghany2222@gmail.com'),
),
));
$calendarId = 'xxxxxxxxx';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s', $event->htmlLink);
$conference = new Google_Service_Calendar_ConferenceData();
$conferenceRequest = new Google_Service_Calendar_CreateConferenceRequest();
$conferenceRequest->setRequestId('randomString123');
$conference->setCreateRequest($conferenceRequest);
$event->setConferenceData($conference);
// ['conferenceDataVersion' => 1] is required!
$event = $service->events->patch($calendarId, $event->id, $event, ['conferenceDataVersion' => 1]);
printf('<br>Conference created: %s', $event->hangoutLink);
// printf('Event created: %s\n', $createdEvent->htmlLink);
我正在使用 google-api-php-客户端
错误:
Google\Service\Exception: { "error": { "errors": [ { "domain": "calendar", "reason": "forbiddenForServiceAccounts", "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." } ], "code": 403, "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." } } in C:\wamp\www\bbb.portal.pfhcheckups.com\app\google-api\src\Http\REST.php on line 128
Service accounts cannot invite attendees without Domain-Wide Delegation of Authority
就是这个意思。只有在 Gsuite (WorkSpace) 域上设置了域范围委托的服务帐户才能邀请人们参加活动。
请您的 Gsuite 管理员设置 domain wide delegation 服务帐户。如果您没有 gsuite 域,请获取一个或使用 Oauth2 来验证用户而不是服务帐户。
如果您已将域范围内的访问权限委派给服务帐户并且您想模拟用户帐户,请使用方法 setSubject:
指定用户帐户的电子邮件地址$client->setSubject($user_to_impersonate);