新手问题,我还不习惯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);
关于PHP Google Calendar API - 更新事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922392/