php - PHP 中的 Google-Calendar-Api 错误,“开始时间和结束时间必须要么都是日期,要么都是日期时间”
问题描述
我正在尝试更新谷歌日历中的事件,我正在使用谷歌日历 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) { } }
解决方案
感谢@Nico Haase,我发现了一个类似的问题
这是更新的代码:
$end_date = new DateTime($string_end_date);
$google_end_time = new Google_Service_calendar_eventDateTime();
$google_end_time->setDateTime($end_date->format(\DateTime::RFC3339));
推荐阅读
- azure - 创建 Azure DPS 时,是否有任何 REST API 以编程方式链接 IoT 中心?
- android - 当我滚动并且视频在屏幕上上下移动时,它会停止。即使不在屏幕上,我也希望视频继续播放
- python - 我无法使用 Windows 32 位命令提示符从此模块导入
- visual-studio-code - 从 WSL 环境访问非路径 WSLENV 变量
- cocoapods - Nativescript NativeAPI 找不到 NSURL、NSURLRequest、NSObject
- java - 类型 T 不是有界参数的有效替代品 `
> - xml - 我的 xml 正在将所有文本值设置为“”的节点更改为没有文本值,我该如何阻止它?
- c++ - 给定总和的子数组
- ios - 插入和更新核心数据对象的有效方法 [2020]
- javascript - 无法在 php-ajax-live-search-with-multiple-value 中显示错误消息“未找到结果”