PHP Google Calendar API - 更新事件

标签 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);

关于PHP Google Calendar API - 更新事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922392/

相关文章:

javascript - 将 Google 日历数据与基于 D3.js 的日历集成

ios - Swift Google 日历帐户注销

php - 连续的分号;不返回语法错误?

php - JQuery .ajax() 调用的空白响应消息长度为 13 个字符?

php - 在 PHP-CS-Fixer 中使用制表符缩进

php - strtolower() 用于 unicode/多字节字符串

android - 如何以编程方式删除我自己的自定义损坏日历?

javascript - 如何跨机器保持google api身份验证?

php - 在 Facebook 应用程序中使用信用卡

Google Calendar API invalid_grant 获取 token (Golang)