【问题标题】:How to get the location of an event in Google Calendar through the Google Calendar API in Javascript?如何通过 Javascript 中的 Google Calendar API 获取 Google Calendar 中事件的位置?
【发布时间】:2021-07-04 10:34:00
【问题描述】:

如标题中所述,我想通过 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.');
        }
    });
}

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

【问题讨论】:

    标签: javascript api location google-calendar-api


    【解决方案1】:

    推荐:

    我已按照JavaScript Quickstart 的指南复制了您的代码,并查看了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.');
          }
        });
      }
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多