2

这是一个新手问题,我还不习惯 Google API


你好,

我正在使用谷歌提供的代码(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

我做错了什么?

谢谢你的帮助。

4

2 回答 2

4

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

试试下面的代码:

$event = $cal->events->get("calendar@gmail.com","longeventcodegivenbygoogle");
$event->setLocation('Somewhere');
$updated = $cal->events->update("calendar@gmail.com", $event->getId(), $event);
于 2012-06-06T22:25:27.747 回答
4

真正的解决方案是由 Claudio Cherubino 通过调用事件类来创建事件对象给出的。

默认情况下,似乎 get() 不返回事件对象,而是返回一个数组。

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

如果您不使用 update() 或 get() 提供的数组创建事件,它将不起作用,因为它是这些调用返回的简单数组。

于 2012-06-07T12:40:21.810 回答