我尝试通过php运行服务器端来使用Google Calendar API。Google Calendar 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 = ...
给出了禁错误...
你好。你可以发布你迄今为止的代码吗?没有看到任何东西,很难说出什么问题。 –
好的,我刚刚编辑了我的问题,并在那里添加了代码。 – blacktemplar