获取 JSON 国定假日列表 Google 日历

Getting JSON with list of national holidays Google Calendar

如何使用 Google 日历 和 javascript 或 jquery 获取所选国家/地区的假期列表?

可能吗?有什么建议吗?

我正在使用 Google Calendar API V3 并使用 javascript。 我在android中找到了一些例子,但我对android一无所知。

这是一个简单的例子,其中包含一些 public holidays calendars:

$("#selectCountry").change(function(e) {
  $("#output").html("Loading...");
  var country = $("#selectCountry").val();
  var calendarUrl = 'https://www.googleapis.com/calendar/v3/calendars/en.' + country 
                  + '%23holiday%40group.v.calendar.google.com/events?key=<yourAPIKey>';

  $.getJSON(calendarUrl)
    .success(function(data) {
     console.log(data);
      $("#output").empty();
      for (item in data.items) {
        $("#output").append(
          "<hr><h3>" + data.items[item].summary + "<h3>" +
          "<h4>" + data.items[item].start.date + "<h4>"
        );
      }
    })
    .error(function(error) {
      $("#output").html("An error occurred.");
    })
});
$("#selectCountry").trigger("change");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>
  <select id="selectCountry">
    <option value="usa">USA</option>
    <option value="uk">UK</option>
    <option value="bm">Bermuda</option>
    <option value="swedish">Sweden</option>
  </select>
  <pre id="output"></pre>
  <script type="text/javascript">
  </script>
</body>

此策略根据在下拉菜单中选择的选项为日历构造一个 URL。它从原始 JSON 响应中解析假日名称和信息,这些响应包含在 $.getJSON 回调函数的 data 参数中。