【问题标题】:PHP Google Calendar API - Updating an eventPHP Google Calendar API - 更新事件
【发布时间】:2015-08-25 01:22:27
【问题描述】:

这是一个新手问题,我还不习惯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

我做错了什么?

感谢您的帮助。

【问题讨论】:

    标签: php google-calendar-api


    【解决方案1】:

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

    试试下面的代码:

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

    【讨论】:

      【解决方案2】:

      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() 提供的数组创建事件,它将不起作用,因为它是这些调用返回的简单数组。

      【讨论】:

      • 看来您需要使用新的 Google_Event
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多