【发布时间】:2017-11-04 22:11:46
【问题描述】:
我尝试通过 php 运行服务器端来使用 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 = ... 给出了禁止的错误...
【问题讨论】:
-
您好。你能发布你到目前为止的代码吗?没有看到任何东西,很难判断出了什么问题。
-
好的,我刚刚编辑了我的问题并在那里添加了代码。
标签: php api google-calendar-api http-status-code-403