admin管理员组

文章数量:1290971

How to get a holiday list of selected country using Google Calendar with javascript or jquery?

It's possible? Any suggestion?

I'm working with Google Calendar API V3 and using javascript. I found some examples in android, but I don't know nothing about android.

How to get a holiday list of selected country using Google Calendar with javascript or jquery?

It's possible? Any suggestion?

I'm working with Google Calendar API V3 and using javascript. I found some examples in android, but I don't know nothing about android.

Share Improve this question edited Nov 3, 2015 at 18:37 Vitor asked Oct 8, 2015 at 13:57 VitorVitor 5212 gold badges4 silver badges28 bronze badges 8
  • Already answered: stackoverflow./questions/18996577/… – Arius Commented Oct 8, 2015 at 14:02
  • I need javascript example, not android. @Arius – Vitor Commented Oct 8, 2015 at 14:06
  • Sorry but what is the difference? You are using API in the same way in all languages... – Arius Commented Oct 8, 2015 at 14:07
  • No, it is not same way. See at: developers.google./google-apps/calendar. Have many ways to start as differents languages. – Vitor Commented Oct 8, 2015 at 14:13
  • developers.google./google-apps/calendar/v3/reference - this is just REST API to consume. Despite the differences of conusming API like this in different languages, you will ALWAYS ask the same endpoints with the same results no matter what language you will use. You can just use $.ajax() call from jQuery to receive results. – Arius Commented Oct 8, 2015 at 14:49
 |  Show 3 more ments

1 Answer 1

Reset to default 7

Here's a simple example with a handful of the public holidays calendars:

$("#selectCountry").change(function(e) {
  $("#output").html("Loading...");
  var country = $("#selectCountry").val();
  var calendarUrl = 'https://www.googleapis./calendar/v3/calendars/en.' + country 
                  + '%23holiday%40group.v.calendar.google./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./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>

This strategy constructs a URL for the calendar from the option selected in the dropdown menu. It parses the holiday name and information from the raw JSON response, which is contained in the data parameter of the $.getJSON callback function.

本文标签: javascriptGetting JSON with list of national holidays Google CalendarStack Overflow