Google calendar

Introducition

There are plenty of services provided by Google, such as gmail, google calendar, google map, google drive etc. A whole list of products may be seen on this About Google - Products. These services may be integrated into developers' application. More information please visit Google developers. The following is a little try out of the Google calendar service.

Demonstration

Setup

  1. Open Google calendar api via Google developer console. Create a new project or choose an existed projects.
  2. Go the credentials.
  3. Select the credentials on the left hand side Credentials
  4. Create credentials and select API key. Create credential
  5. Enter the url of the webpage. Url

Code

This piece of code declares three functions, while appendResults would append the returning results of the querying events from 2016-02-24 to 2016-06-26, makeRequest would make a request to the Google calendar service, and init would set up the api key and load the calendar object. The following two script would load the google javascript api and call the function init after loading.
<script>
  function appendResults(text) {
    var results = document.getElementById('results');
    for (var i = 0; i < text.items.length; i++) {
      var li = document.createElement('li');
      li.appendChild(document.createTextNode(text.items[i].summary));
      document.getElementById('results').appendChild(li);
    }
  }
  function makeRequest(){
  	var request = gapi.client.calendar.events.list({
      'calendarId': 'f6i3vqb0ogfabog28dg2d7s5g4@group.calendar.google.com',
      'start': new Date("2016-02-24").toISOString(),
      'end': new Date("2016-06-26").toISOString()
    });
  	request.execute(appendResults);
  }
  function init() {
    gapi.client.setApiKey('AIzaSyBYt_lOEaWT552UNXGV7s3Mwth_DP-A2ac');
  	
    gapi.client.load('calendar', 'v3').then(makeRequest);
  }
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		

Conclusion

Including the Google calendar in an applications may utilize the calendar functions provided Google. There are more examples and apis may be found on Google calendar reference.

History

First revision: add description - 2016/02/27

Reference

  1. Google products
  2. Google developers
  3. Google calendar developer quick start javascript