Php 谷歌日历API获取事件

Php 谷歌日历API获取事件,php,google-api,google-calendar-api,Php,Google Api,Google Calendar Api,我想从谷歌日历上获取一个事件,基于它的ID,并更新其中的一些数据 $client = $this->getClient(); $service = new Google_Service_Calendar($client); $calendarId = 'primary'; $optParams = array( 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => date('

我想从谷歌日历上获取一个事件,基于它的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
      帐户。要查看您帐户中的所有可用日历,您可以将其与以下内容一起列出:
    • eventId
      :要更新的事件的
      id
      。您可以使用以下选项列出特定日历中的所有可用事件:
    代码
    我收到一个错误,那么您收到了什么错误?抱歉,我更新了问题。calendarList.get与获取单个事件无关。Calendarlist是UI左下方的列表。不保证会填充日历列表,如果您想要日历,请插入它。谢谢!在开始的时候,我还必须编写$client->setScopes(Google_Service_Calendar::Calendar_EVENTS)。起初我有日历。
    $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);