Javascript 如何从谷歌日历API获取当前事件?

Javascript 如何从谷歌日历API获取当前事件?,javascript,google-calendar-api,google-api-js-client,Javascript,Google Calendar Api,Google Api Js Client,我现在正尝试使用Google日历API方法检索日历上的事件 我可以成功筛选开始日期和结束日期。但是,如果某个活动是昨天开始的,并且仍在进行中,过滤从今天开始的内容对我没有帮助 var request = gapi.client.calendar.events.list({ 'calendarId': 'my calendar id', // shows things that have not yet started 'timeMin': (new D

我现在正尝试使用Google日历API方法检索日历上的事件

我可以成功筛选开始日期和结束日期。但是,如果某个活动是昨天开始的,并且仍在进行中,过滤从今天开始的内容对我没有帮助

    var request = gapi.client.calendar.events.list({
      'calendarId': 'my calendar id',
      // shows things that have not yet started
      'timeMin': (new Date()).toISOString(),
      'showDeleted': false,
      'singleEvents': true,
      'orderBy': 'startTime'
    });
如何在日历上找到当前正在进行的事情列表


我(显然)希望避免提取一周的事件并对其进行解析。

没有直接查询当前事件的方法,但您当然可以给它一个有限的最短和最长时间,因此您只能搜索少量事件。如果你的活动是有规律的,并且持续时间可以预测,那么你就可以只给你一次

events = client.events().list(calendarId='primary',
                              timeMin='2011-12-22T09:00:00Z',
                              timeMax='2011-12-22T22:00:00Z').execute()

有关更多信息,请阅读Google Calendar API的官方文档:

,因此我来此线程搜索相同的答案,但没有结果,因此以下是您可以做的:

    $data = self::$service->events->listEvents(self::$calendarId, $optParams);
    $curr_time = time();
    $active_meetings = array();

    if (count($data->getItems()) > 0) {  
        foreach ($data->getItems() as $event) {
            $start = date("U", strtotime($event->start->dateTime));
            $end   = date("U", strtotime($event->end->dateTime));
            if(($start > $curr_time) && ($end < $curr_time))
            {
                $active_meetings[$event->id] = $event->summary;
            }   
        }
    }
    return $active_meetings;
$data=self::$service->events->listEvents(self::$calendarId,$optParams);
$curr_time=time();
$active_meetings=array();
如果(count($data->getItems())>0){
foreach($data->getItems()作为$event){
$start=date(“U”,strottime($event->start->dateTime));
$end=date(“U”,strottime($event->end->dateTime));
如果($start>$CURRU time)&($end<$CURRU time))
{
$active_meetings[$event->id]=$event->summary;
}   
}
}
返回$active_会议;
这里只需将事件恢复到事件前1小时,然后将事件的开始时间和结束时间与当前时间进行比较


这将列出当前正在发生的事件。谢谢

是的,但是如果现在有活动在我的时间之前开始,那对我没有帮助。例如,如果两天前开始了一个为期一周的活动,并且我将timeMin设置为今天开始,那么我将不会看到为期一周的活动。