PHP Google Calendar API - 更新事件

新手问题,我还不习惯Google API


你好,

我使用的是 Google ( https://developers.google.com/google-apps/calendar/downloads ) 提供的代码,其中包含一些示例(最初是因为它似乎是最新的)。

我正在成功检索日历,如示例“calendar/simple.php”所示(OAuth2 设置正确)。

在那之后,我正在这样做并且它有效(这是一个不必要的代码,只是为了检查是否可以正确检索事件而没有任何错误):

$test = $cal->events->get("calendar@gmail.com","longeventcodegivenbygoogle");

现在,我希望能够设置特定事件的一些值。

$event = new Event();
$event->setLocation('Somewhere');
$test = $cal->events->update("calendar@gmail.com","longeventcodegivenbygoogle",$event);

但它给了我:

( ! ) Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling PUT https://www.googleapis.com/calendar/v3/calendars/calendar@gmail.com/events/longeventcodegivenbygoogle?key=myapikey: (400) Required' in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86
( ! ) apiServiceException: Error calling PUT https://www.googleapis.com/calendar/v3/calendars/calendar@gmail.com/events/longeventcodegivenbygoogle?key=myapikey: (400) Required in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86

我做错了什么?

感谢您的帮助。

最佳答案

为了更新事件,您首先检索它,然后更改其属性的值,而不是实例化一个新的。

试试下面的代码:

$event = $cal->events->get("calendar@gmail.com","longeventcodegivenbygoogle");
$event->setLocation('Somewhere');
$updated = $cal->events->update("calendar@gmail.com", $event->getId(), $event);

https://stackoverflow.com/questions/10922392/

相关文章:

variables - Makefile 字符串变量

sql-server-2008 - 一个选择语句中的不同条件

groovy - Groovy 中的 JUnit @Before 方法排序

regex - 检查目录是否存在递归地反转路径

sql - 如何优化此 SQL 查询(使用索引)?

css - 向右浮动和小时对齐

php - MySQLi 查询以获取表中的最大 id?

email - 使用 ssl 的 Yandex smtp 设置

string - 将字符串/字符转换为 uint8

caching - 什么是暖缓存?