将事件开始日期从“date”更改为“dateTime”

时间:2016-02-26 15:15:34

标签: google-calendar-api google-php-sdk

我正在尝试使用Google API Explorer

修补具有新的开始日期和结束日期的现有事件

所以我此刻的活动看起来像这样

{
 "kind": "calendar#event",
 "etag": "\"2912997881756000\"",
 "id": "3fpkrr85sdfdgsdfsdsdflgn7vk74qhiv2o",
 "status": "confirmed",
 "htmlLink": "https://www.google.com/calendar/event?eid=M2Zwa3JsdfsdfyODVudWZobGduN3ZrNzRxaGl2Mm8gZHlsbsdfsdfi5pb19xNjUwcWRhcnYyam9vYWYzcTdudmhpc2ZvNEBn",
 "created": "2016-02-26T14:32:33.000Z",
 "updated": "2016-02-26T15:02:20.878Z",
 "summary": "aaaa",
 "creator": {
  "email": "xxxx@yyy.com",
  "displayName": "name"
 },
 "organizer": {
  "email": "xxxxxx@group.calendar.google.com",
  "displayName": "Display",
  "self": true
 },
 "start": {
  "date": "2016-02-26"
 },
 "end": {
  "date": "2016-03-02"
 },
 "iCalUID": "3fpkrr85nufasdfsdfsadfasdfhlgn7vk74qhiv2o@google.com",
 "sequence": 2,

 "reminders": {
  "useDefault": true
 }
}

我从Google API Explorer发出的请求就是这样的

PATCH https://www.googleapis.com/calendar/v3/calendars/ddfdfdfdfdf%40group.calendar.google.com/events/3fpkrr85nufhlgn7sdfsafdfdsghgffdhvk74qhiv2o?fields=start&key={YOUR_API_KEY}

{
 "start": {
  "dateTime": "2016-02-16T12:00:00+01:00"
 },
 "end": {
  "dateTime": "2016-02-18T13:00:00+01:00"
 }
}

但我总是得到以下错误

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid start time."
   }
  ],
  "code": 400,
  "message": "Invalid start time."
 }
}

我猜这种情况正在发生,因为该事件是一个All Day事件,这意味着start是一个Date字段而我正在发送DateTime但这正是我的意思想做。我不能简单地将startend的类型从Date更改为DateTime吗?

更新

这是路径请求的php代码

$client = $this->container->get('google.calendar.client');
                $client->setAccessToken($this->auth()->getIdentity()->getGoogleAccessToken());
                $service = new \Google_Service_Calendar($client);
                $event = new \Google_Service_Calendar_Event($eventData);
                $event = $service->events->patch($this->auth()->getIdentity()->getGoogleCalendarId(), $item->getGoogleId(), $event);
                $item->setGoogleId($event->getId());
                $this->getItemRepo()->save($item);

2 个答案:

答案 0 :(得分:5)

剩余日期似乎存在问题。将日期显式设置为null可以起作用:

{
 "start": {
  "dateTime": "2016-02-16T12:00:00+01:00",
  "date": null
 },
 "end": {
  "dateTime": "2016-02-18T13:00:00+01:00",
  "date": null
 }
}

答案 1 :(得分:0)

我知道这是一个旧线程,但是我在PHP SDK中遇到了同样的错误,因此也得到了简短的信息:在PHP SDK中,Goole_Model类Google_Model::NULL_VALUE中存在空值常量。如果您不使用此设置,则所有设置为“普通” null的字段都会被删除,并且永远不会发送到Google API,从而导致补丁请求失败。