php - 创建活动 Google 日历错误
问题描述
我是一名初级程序员,也是谷歌日历 API 的新手。我想使用谷歌提供的代码创建一个事件来创建一个事件,问题是我只能获取我即将发生的事件的列表,但我无法创建一个事件。
此代码有效:https ://developers.google.com/calendar/quickstart/php
我把这段代码放在另一个下面:
$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' => '2018-08-28T09:00:00-07:00',
'timeZone' => 'Europe/Brussels',
),
'end' => array(
'dateTime' => '2018-08-28T17:00:00-07:00',
'timeZone' => 'Europe/Brussels',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => 'stefanos.stoikos@gmail.com'),
array('email' => 'stefanos.stoikos@gmail.com'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
当我在 cmd 中执行此操作时,出现以下错误:
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
' in C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src\Google\Http\REST.php:118
Stack trace:
#0 C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src\Google\Http\REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src\Google\Task\Runner.php(176): call_user_func_array(Array, Array)
#3 C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src\Google\Http\REST.php(58): Google_Task_Runner->run()
#4 C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src in C:\xampp\htdocs\StefanosProject\vendor\google\apiclient\src\Google\Http\REST.php on line 118
我尝试了不同的解决方案来创建一个事件,但我一直有错误,有人可以帮我吗?
解决方案
您的创建事件代码可能是正确的,但您需要为要添加事件的用户配置 oauth:
https://developers.google.com/calendar/create-events
具体在这里查看这部分:
In order to successfully create events, you need to:
* set your OAuth scope to https://www.googleapis.com/auth/calendar.
ensure the authenticated user has write access to the calendar
* with the calendarId you provided (for example by calling calendarList.get() for the calendarId and checking the accessRole).
这是一个更长的教程,包括设置和使用 oauth: http ://usefulangle.com/post/29/google-calendar-api-create-event-php
推荐阅读
- office-js - 任务窗格在最新版本的 OfficeJS Excel 中不起作用
- typescript - TypeScript 中的对象动态属性访问
- symfony - 使用集合处理 Formbuilder 上的 OneToMany 字段
- java - 如何将二维数组或任何数组专门转换为列表
- > 在 Java 8 中?
- c# - 不一致的JArray如何计算
- javascript - onsubmit 表单不起作用需要显示一些验证
- java - 我的 mergeSort 实现有问题
- c++ - C ++中的井字游戏,再次播放功能问题
- sql - 将 ROW_NUMBER 列添加到流式数据帧
- javascript - 如何使用 Javascript 滚动特定节点给定数量的像素?