簡體   English   中英

如何通過 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.');
        }
    });
}

現在不起作用的部分是“位置”。 我能夠獲得接下來 10 個日歷事件的日期和名稱,但不能獲得位置。 有誰知道如何做到這一點? 提前致謝!!

推薦:

我已經按照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.');
      }
    });
  }

結果如下:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM