Accessing the Google Calendar

A workaround for accessing your Google calendar info.

You can use any Google calendar feed either a public one or even a private feed of your own or any other calendar.

About getting the calendar feed link http://support.google.com/calendar/bin/answer.py?hl=en&answer=37103

IMPORTANT This method uses the device.ajax() call which will use up data. You can try using partial response to get only the fields you need for a recipe https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol#PartialResponse

To use this on{X} Recipe, simply copy the code below and modify if needed.

var feed = âhttps://www.google.com/calendar/feeds/your_calendar_path_here/fullâ;
    
// make sure to use "alt=json"
var params =  âalt=json&ctz=UTC&max-results=5&singleevents=false&futureevents=true&orderby=starttime&sortorder=ascendingâ;

 // call the feed and get to working
 device.ajax({url: feed +â?'+ params,
              type: âGETâ,
              headers: {âContent-Typeâ: âapplication/jsonâ}
             },
             function onSuccess(body, textStatus, response) {
                 console.log(textStatus);
                 var feed;
                 if (!(body && (feed = JSON.parse(body)))) {
                     console.error(âinvalid body formatâ);
                     return;
                 }
                 feed = feed.feed;
                 var eventCount = feed.entry.length;
                 console.info(âgot â+ eventCount +â events for â+ feed.title.$t);
                 // check upcoming events
                 for (var i = 0; i < eventCount; i++) {
                     var eventEntry = feed.entry[i];
                     console.log('event ' + eventEntry.title.$t);
                     var notification = device.notifications.createNotification('View ' + eventEntry.title.$t);
                     notification.content = 'Click to open';
                     // the link is recognized by the device, and can will open the event details on the device
                     notification.on('click', function() {
                            device.browser.launch(eventEntry.link[0].href);
                      });
                      notification.show();
                 }
             },
             function onError(textStatus, response) {
                 console.error(textStatus);
             });

Recipe Wall

1,094

Views