【问题标题】:Google-Calendar-Api Error in PHP, "Start and end times must either both be date or both be dateTime" [duplicate]PHP中的Google-Calendar-Api错误,“开始和结束时间必须都是日期或都是日期时间”[重复]
【发布时间】:2019-07-11 08:02:57
【问题描述】:

我正在尝试更新 google 日历中的事件,我正在使用 google calendar api,但是当我尝试设置事件的开始日期时间和结束日期时间时,我收到此错误:

 "code": 400, "message": "Start and end times must either both be date or both be dateTime." .

我实际上尝试将我的日期格式化为 ISO8601 和 RF3339,但我会在日期格式无效的情况下得到不同类型的错误

这是我的代码

$service = new Google_Service_Calendar($client);
  $event = $service->events->get($calendarID, $eventId);

$string_start_date ="12-07-2020 07:13:00"
  $start_date = new DateTime($string_start_date);
    $google_start_time = new Google_Service_calendar_eventDateTime();
      $google_start_time->setDateTime($start_date);

$string_end_date = "13-07-2020 12:00:00";
  $end_date = new DateTime($string_end_date);
    $google_end_time = new Google_Service_calendar_eventDateTime();
      $google_end_time->setDateTime($end_date);

$event->setDescription("description");
$event->setEnd($google_end_time);
$event->setStart($google_start_time);
$event->setSummary("summary");

$update = $service->events->update($calendarID, $eventId, $event);

这是我的两个 google_service_calendar_eventDateTime 对象的内容:

1:object(Google_Service_Calendar_EventDateTime)#31 (6) { ["date"]=> NULL ["dateTime"]=> object(DateTime)#52 (3) { ["date"]=> string(26) "2020-07-12 07:13:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["timeZone"]=> NULL ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } }

2:object(Google_Service_Calendar_EventDateTime)#58 (6) { ["date"]=> NULL ["dateTime"]=> object(DateTime)#73 (3) { ["date"]=> string(26) "2020-07-13 12:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["timeZone"]=> NULL ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } }

【问题讨论】:

  • 您还尝试了哪些其他方法?这会产生哪些其他错误消息?

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


【解决方案1】:

感谢@Nico Haase,我发现了一个类似的问题

This is the link where i found the answer

这是更新后的代码:

$end_date = new DateTime($string_end_date);
   $google_end_time = new Google_Service_calendar_eventDateTime();
     $google_end_time->setDateTime($end_date->format(\DateTime::RFC3339));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多