【问题标题】:Get only the updated events from google calendar using google client php api使用谷歌客户端 php api 仅从谷歌日历获取更新的事件
【发布时间】:2016-02-12 06:10:23
【问题描述】:

我正在尝试将谷歌日历与我的网站同步。我正在使用谷歌客户端 php api。到目前为止,我能够从谷歌日历中获取所有事件。有没有办法只从谷歌日历中获取更新的事件。 下面是从谷歌日历获取事件的代码

$client = new Google_Client();

$client->setApplicationName( $app_name ); 
$client->setDeveloperKey( $app_key ); 
$cal = new Google_Service_Calendar( $client );
$calendarId = $app_id;

$params = array(      
  'singleEvents' =>   true,
  'orderBy'      =>   'startTime',
);
$events = $cal->events->listEvents($calendarId, $params);
foreach ( $events->getItems() as $event ) {
echo $event->getSummary();
}

【问题讨论】:

    标签: php api google-api google-calendar-api


    【解决方案1】:

    我猜你只能使用orderBy 参数。它有一个值“updated”,按上次修改时间(升序)对事件进行排序。这是documentation

    【讨论】:

    • @user5916491 感谢您的回复..我使用参数“更新”事件按上次修改的事件排序。但显示所有事件。我只需要修改的事件而不是所有事件.有什么办法可以做到这一点..?
    • 不,这不起作用。如果您修改一个事件(事件实例),然后修改整个系列,您将获得具有相同updated 时间的所有事件实例。
    【解决方案2】:

    我正在研究相同的功能,但显然他们的公共 Google 日历 API 不允许这样做。似乎唯一的方法是获取主重复事件并将其与所有事件实例(逐个字段)进行比较。我敢打赌,他们有一个内部 API,可为内部日历同步提供该信息。

    抱歉,没有 PHP 代码,我使用 C# 和 REST API。

    【讨论】:

      【解决方案3】:

      在 API v3 中,您可以使用参数 updatedMin。

       $datetime = \DateTime::createFromFormat("Y-m-d H:i:s", "2019-07-14 05:40:00");
      
       $events = $service->events->listEvents('primary', [
         "updatedMin" => $datetime->format(\DateTime::RFC3339)
       ]);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-28
        • 1970-01-01
        • 2018-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多