[英]Google Calendar API get an event
我想从谷歌日历中获取一个事件,基于它的 ID 并更新它的一些数据。
$client = $this->getClient();
$service = new Google_Service_Calendar($client);
$calendarId = 'primary';
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
$events = $results->getItems();
上面的代码适用于所有事件和作品。
$client = $this->getClient();
$service = new Google_Service_Calendar($client);
$calendar = $service->calendarList->get($calendarId);
上面的代码是针对单个事件的,我收到请求时出错。 从我所看到的情况来看,我需要第二个参数,例如$optParams
,但我不确定该参数具有什么价值。
错误信息。
PHP Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
in ..\vendor\google\apiclient\src\Google\Http\REST.php:123
Stack trace:
#0 ..\vendor\google\apiclient\src\Google\Http\REST.php(98): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 ..\vendor\google\apiclient\src\Google\Task\Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 ..\vendor\google\apiclient\src\Google\Http\REST.php(61): Google_Task_Runner->run()
#3 C:\xampp\sites\calmnest\wp-content\plugins\nrc- in ..\vendor\google\apiclient\src\Google\Http\REST.php on line 123
您收到错误是因为您没有使用正确的方法
这两种方法都使用两个查询参数: calendarId
和eventId
:
calendarId
:您可以编写primary
帐户或gmail
帐户。 为了查看您帐户中所有可用的日历,您可以使用以下命令列出它们: CalendarList: listeventId
:要更新的事件的id
。 您可以列出特定日历中的所有可用事件:事件:列表$calendarId = 'primary';
$eventId = 'eventId';
// Get Event
$event = $service->events->get($calendarId, $eventId);
// Modify Event
$event->setSummary('New title');
$event->setDescription('New describtion');
// Update Event
$updatedEvent = $service->events->update($calendarId, $eventId, $event);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.