Category Archives: Google APIs

Finding the ID’s of All Calendars attached to a Google Account

14 Sep 2015

If you work with Google Calendars you know that you need to specify the ID of a calendar in order to be able to update it. A small modification to the code provided by Google will print all your calendar objects to the console and then you can find the specific calendar’s ID.

Be sure to read this over at Google: Authentication using the Google APIs Client Library for JavaScript. Specifically you need to generate the access keys for your application before you can call the calendar.calendarList.list method to see all the calendars in your account.

I won’t walk through the whole thing – see below and note the comments (As an aside this was relevant to something I did that inserted calendar entries into a Google calendar – see this repo).

    var CLIENT_ID = 'your_client_id'
    var SCOPES = [''];

    // Check if current user has authorized this application.
    function checkAuth() {
            'client_id': CLIENT_ID,
            'scope': SCOPES,
            'immediate': true
          }, handleAuthResult);

    //* Handle response from authorization server.
    //* @param {Object} authResult Authorization result.
    function handleAuthResult(authResult) {
        var authorizeDiv = document.getElementById('authorize-div');
        if (authResult && !authResult.error) {
          // Hide auth UI, then load client library.
 = 'none';
        } else {
          // Show auth UI, allowing the user to initiate authorization by
          // clicking authorize button.
 = 'inline';

    //* Initiate auth flow in response to user clicking authorize button.
    //* @param {Event} event Button click event.
    function handleAuthClick(event) {
          {client_id: CLIENT_ID, scope: SCOPES, immediate: false},
        return false;

    //* Load Google Calendar client library. List upcoming events
    //* once client library is loaded.
    function loadCalendarApi() {
        // Now get the list of calendars for the primary google account
        gapi.client.load('calendar', 'v3', function() {
            var request = gapi.client.calendar.calendarList.list({
		 'calendarId': 'primary'
		 request.execute(function(resp) {
		 for (var i = 0; i < resp.items.length; i++) {

Also, place the following in your html:

    <div id="authorize-div" style="display: ">
      <span>Authorize access to Google Calendar API
      <!--Button for the user to click to initiate auth sequence -->
      <button id="authorize-button" onclick="handleAuthClick(event)">
    <pre id="output"></pre>

Using the Google Maps API to Get Locations from Zip Codes

14 Sep 2012

Google offers many API’s, among them is the Maps API. In this example we’ll show all the code necessary to hit Google with a zip code to get the location in the form of City, State and Country.

As of June 22, 2016 you **must** apply for a Google Maps API key. All sites that use the service prior to June 22 will be grandfathered into the Google Maps service for keyless usage (Read this post from the Google Geo Developers Blog). Any new applications must include an API key so that Google can enforce rate limiting. If you see this error message: “MissingKeyMapError” – you are trying to use the Google Maps Service without a key – the fix is simply to acquire and start using an API key.

First thing to do is to reference Google’s Map API:

<script language="javascript" src=""></script>

Next is a little form used to enter your zip code:

zip: \<input type="text" name="zip" value="46032"> <a href="#" onclick="getLocation()">Get Address</a>

You can see that I have a link which fires a function called “getLocation()” – below you’ll find that function and the related code:

function getLocation(){

function response(obj){
function getAddressInfoByZip(zip){
  if(zip.length >= 5 && typeof google != 'undefined'){
    var addr = {};
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': zip }, function(results, status){
      if (status == google.maps.GeocoderStatus.OK){
        if (results.length >= 1) {
	  for (var ii = 0; ii < results[0].address_components.length; ii++){
	    var street_number = route = street = city = state = zipcode = country = formatted_address = '';
	    var types = results[0].address_components[ii].types.join(",");
	    if (types == "street_number"){
	      addr.street_number = results[0].address_components[ii].long_name;
	    if (types == "route" || types == "point_of_interest,establishment"){
	      addr.route = results[0].address_components[ii].long_name;
	    if (types == "sublocality,political" || types == "locality,political" || types == "neighborhood,political" || types == "administrative_area_level_3,political"){ = (city == '' || types == "locality,political") ? results[0].address_components[ii].long_name : city;
	    if (types == "administrative_area_level_1,political"){
	      addr.state = results[0].address_components[ii].short_name;
	    if (types == "postal_code" || types == "postal_code_prefix,postal_code"){
	      addr.zipcode = results[0].address_components[ii].long_name;
	    if (types == "country,political"){ = results[0].address_components[ii].long_name;
	  addr.success = true;
	  for (name in addr){
	      console.log('### google maps api ### ' + name + ': ' + addr[name] );
        } else {
      } else {
  } else {

Thats it - open up the console in Chrome and notice the output as you enter different zip codes.


All content © 2012-2017.