Google 日历 API - 禁止 - 服务帐户错误
Google Calendar API - Forbidden - Error with Service Account
我尝试通过 php 运行 服务器端使用 Google 日历 API。
我创建了一个服务帐户并使用了它的凭据(通过 json 文件)。我没有使用 G Suite。
现在我可以列出日历中的事件,但是当我尝试创建新事件时出现禁止 - 错误。
我与服务帐户的电子邮件地址共享了我的日历,并授予其日历的管理员权限。我不知道我做错了什么!我只是无法让它工作。我也在使用范围 Google_Service_Calendar::CALENDAR.
异常:403 - 禁止访问
我不知道如何调试这个问题以及如何进一步处理。
你能帮帮我吗?
编辑:这是我的调用代码:
putenv('GOOGLE_APPLICATION_CREDENTIALS=../google-service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes([Google_Service_Calendar::CALENDAR]);
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event([
'summary' => $name,
'location' => $location,
'description' => $desc,
'start' => [
'dateTime' => $start,
'timeZone' => $timezone,
],
'endTimeUnspecified' => true,
]);
$calendar = $service->calendars->get($calendarId);
$settings = $service->settings->listSettings();
$list = $service->acl->listAcl($calendarId);
$event = $service->events->insert($calendarId, $event);
前三个服务调用($calender = ...
、$settings = ...
和 $list = ...
)工作正常,在 acl 中我还可以看到我的服务帐户的电子邮件地址拥有所有权限(角色:所有者)。但是最后一行 $event = ...
给出了禁止的错误...
'endTimeUnspecified' => true,
导致你的问题(谷歌的错,但你不能告诉他们)
如果你改为
'end' => [
'dateTime' => $start2,
'timeZone' => $timezone,
],
它会工作(我知道这不是你想要的,也许你可以想办法调整 $start2 给你你想要的结束时间,但 endTimeUnspecified 是导致它说 403 的原因禁止
我尝试通过 php 运行 服务器端使用 Google 日历 API。
我创建了一个服务帐户并使用了它的凭据(通过 json 文件)。我没有使用 G Suite。
现在我可以列出日历中的事件,但是当我尝试创建新事件时出现禁止 - 错误。
我与服务帐户的电子邮件地址共享了我的日历,并授予其日历的管理员权限。我不知道我做错了什么!我只是无法让它工作。我也在使用范围 Google_Service_Calendar::CALENDAR.
异常:403 - 禁止访问
我不知道如何调试这个问题以及如何进一步处理。
你能帮帮我吗?
编辑:这是我的调用代码:
putenv('GOOGLE_APPLICATION_CREDENTIALS=../google-service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes([Google_Service_Calendar::CALENDAR]);
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$service = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event([
'summary' => $name,
'location' => $location,
'description' => $desc,
'start' => [
'dateTime' => $start,
'timeZone' => $timezone,
],
'endTimeUnspecified' => true,
]);
$calendar = $service->calendars->get($calendarId);
$settings = $service->settings->listSettings();
$list = $service->acl->listAcl($calendarId);
$event = $service->events->insert($calendarId, $event);
前三个服务调用($calender = ...
、$settings = ...
和 $list = ...
)工作正常,在 acl 中我还可以看到我的服务帐户的电子邮件地址拥有所有权限(角色:所有者)。但是最后一行 $event = ...
给出了禁止的错误...
'endTimeUnspecified' => true,
导致你的问题(谷歌的错,但你不能告诉他们)
如果你改为
'end' => [
'dateTime' => $start2,
'timeZone' => $timezone,
],
它会工作(我知道这不是你想要的,也许你可以想办法调整 $start2 给你你想要的结束时间,但 endTimeUnspecified 是导致它说 403 的原因禁止