从Google日历API v2到V3-Javascript

从Google日历API v2到V3-Javascript,javascript,web,google-api,google-calendar-api,Javascript,Web,Google Api,Google Calendar Api,当我看到API的V2将在不到一年的时间内被弃用时,我只是在用Javascript开发一个从google日历获取事件的工具。这显然毁了我的一天 所以我试着熟悉这个新的API,但仍然有一些东西我没有发现。 如何在google calendar API v3的javascript客户端上实现参数futureevents=true的等效性 <script type="text/javascript"> var apiKey = 'apikey'; var scopes = '

当我看到API的V2将在不到一年的时间内被弃用时,我只是在用Javascript开发一个从google日历获取事件的工具。这显然毁了我的一天

所以我试着熟悉这个新的API,但仍然有一些东西我没有发现。 如何在google calendar API v3的javascript客户端上实现参数futureevents=true的等效性

<script type="text/javascript">
    var apiKey = 'apikey';
    var scopes = 'https://www.googleapis.com/auth/calendar';

    function handleClientLoad() {
  gapi.client.setApiKey(apiKey);
  makeApiCall();
    }

    function makeApiCall() {
        gapi.client.load('calendar', 'v3', function() {
           var request = gapi.client.calendar.events.list({
               'calendarId': 'idcalendar@group.calendar.google.com'
            });
        request.execute(function(resp) {
           console.log(resp);
           for (var i = 0; i < resp.items.length; i++) {
               var title = document.createTextNode(resp.items[i].summary); 
               var description = document.createTextNode(resp.items[i].description + ' ');
               var location = document.createTextNode(resp.items[i].location + ' ');
               var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date);

               var div = document.createElement('div');
               var h1 = document.createElement('h1');
               h1.appendChild(title);
               div.appendChild(location);
               div.appendChild(description);
               div.appendChild(h1);
               var p = document.createElement('p');
               p.appendChild(date);
               div.appendChild(p);
               document.body.appendChild(h1);
               document.body.appendChild(div);
             }
          });
       }
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
这是我的代码,有了它,我可以得到日历上所有的事件,我怎么能只得到一个还没有发生的事件呢

提前感谢

使用events.list API调用的timeMin参数只请求现在之后的事件

var request = gapi.client.calendar.events.list({
           'calendarId': 'idcalendar@group.calendar.google.com',
           'timeMin': '2013-05-09T09:43:00-04:00'
        });

您可能需要使用日期格式,我不完全确定值应该是什么类型,但您只需要获取当前日期时间并发送它。

如Jay Lee所说,但为了使用timeMin,您还需要将“singleEvents”设置为true。我还包括了一个正确的日期时间字符串

var request = gapi.client.calendar.events.list({
        'calendarId': 'idcalendar@group.calendar.google.com',
        'singleEvents': true, /* required to use timeMin */ 
        'timeMin': '2013-02-01T11:43:22.000Z'
    });