如何通过Javascript中的Google日历API获取Google日历中事件的位置?

How to get the location of an event in Google Calendar through the Google Calendar API in Javascript?

如标​​题所述,我想通过 Javascript 中的 Google 日历 API 获取 Google 日历中事件的位置。因此我使用了 Google API 示例。

/**
 * Print the summary and start datetime/date of the next ten events in
 * the authorized user's calendar. If no events are found an
 * appropriate message is printed.
 */
function listUpcomingEvents() {
    gapi.client.calendar.events.list({
        'calendarId': 'primary',
        'timeMin': (new Date()).toISOString(),
        'showDeleted': false,
        'singleEvents': true,
        'location': '--4-Bikini Bottom (12)',
        'maxResults': 10,
        'orderBy': 'startTime'


    }).then(function (response) {
        var events = response.result.items;
        appendPre('Upcoming events:');

        if (events.length > 0) {
            for (i = 0; i < events.length; i++) {
                var event = events[i];
                var when = event.start.dateTime;
                if (!when) {
                    when = event.start.date;
                }
                appendPre(event.summary + ' (' + when + ')')
            }
        } else {
            appendPre('No upcoming events found.');
        }
    });
}

现在不起作用的部分是'location'。我能够获取接下来 10 个日历事件的日期和名称,但不能获取位置。有谁知道如何做到这一点?提前致谢!!

建议:

我已经按照 JavaScript Quickstart and reviewing the additional info from Events 中的指南复制了您的代码。我可以通过添加 event.location 来调整 appendPre() 行之一,以显示我在日历上创建的即将到来的测试事件的位置,如下所示:

  function listUpcomingEvents() {
    gapi.client.calendar.events.list({
      'calendarId': 'primary',
      'timeMin': (new Date()).toISOString(),
      'showDeleted': false,
      'singleEvents': true,
      'maxResults': 10,
      'orderBy': 'startTime'
    }).then(function(response) {
      var events = response.result.items;
      appendPre('Upcoming events:');

      if (events.length > 0) {
        for (i = 0; i < events.length; i++) {
          var event = events[i];
          var when = event.start.dateTime;
          if (!when) {
            when = event.start.date;
          }
          appendPre(event.summary + ' (' + when + ')\n'+'Location: '+event.location)
        }
      } else {
        appendPre('No upcoming events found.');
      }
    });
  }

结果如下: