[英]Create event Google calendar error
我是一名新手,也是Google日歷API的新手。 我想使用google提供的代碼創建一個活動,以創建一個活動,問題是我只能獲取即將發生的活動的列表,但無法創建活動。
此代碼有效: 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
這就是正在發生的事情。 您引用的PHP快速入門使用read-only
范圍CALENDAR_READONLY
。 但是,您要執行的操作需要寫作用域,因為您要創建事件 。 因此,將您的范圍更改為https://www.googleapis.com/auth/calendar
或任何其他PHP語言版本。
更改后,請不要忘記刪除以前保存的憑據,以使新作用域生效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.