node.js - How do I troubleshoot freebusy google calendar nodejs api? -
i trying free-busy information google calendar using nodejs api listed here https://developers.google.com/google-apps/calendar/v3/reference/freebusy/query. problem error response 'invalid request'. when run google's try tool, able response though. know getting authorized client. can troubleshoot further?
function getavail(auth, datetimerange, calid) { var deferred = q.defer(); // new deferral calendar.freebusy.query({ auth: auth, items: [{id: calid}], timemin: (datetimerange.start).toisostring(), timemax: (datetimerange.end).toisostring(), }, function(err, response) { console.log('response calendar service: ' + response); if (err) { console.log('there error contacting calendar service: ' + err); deferred.reject(); // deferred reject here return; } var events = response[calid]['busy']; if (events.length == 0) { console.log('no upcoming events found.'); } else { console.log('busy in here...'); } deferred.resolve(response); // deferred resolve here }); return deferred.promise; // return promise
}
phew! figured out doing wrong. here code works comments making mistake. wish there better way finding out issue.
function getavail(auth, datetimerange, calid) { console.log('auth:'+json.stringify(auth)); console.log('date time range :'+(datetimerange.start).toisostring()+' --->'+(datetimerange.end).toisostring()); console.log('calendar id check freebusy:'+calid); var deferred = q.defer(); // new deferral calendar.freebusy.query({ auth: auth, headers: { "content-type" : "application/json" }, resource:{items: [{"id" : calid}], //needed include resource instead of sending params directly. timemin: (datetimerange.start).toisostring(), timemax: (datetimerange.end).toisostring() } }, function(err, response) { console.log('response calendar service: ' + json.stringify(response)); if (err) { console.log('there error contacting calendar service: ' + err); deferred.reject(); // deferred reject here return; } var events = response.calendars[calid].busy; if (events.length == 0) { console.log('no upcoming events found.'); } else { console.log('busy in here...'); } deferred.resolve(response); // deferred resolve here }); return deferred.promise; // return promise }
it lot of meditation , staring @ documentation closely. google's nodejs library not particularly well-documented examples yet (well, still alpha). here function freebusy: this.freebusy = {
/** * calendar.freebusy.query * * @desc returns free/busy information set of calendars. * * @alias calendar.freebusy.query * @memberof! calendar(v3) * * @param {object} params - parameters request * @param {object} params.resource - request body data** <<<< -- missing. * @param {callback} callback - callback handles response. * @return {object} request object */ query: function(params, callback) { var parameters = { options: { url: 'https://www.googleapis.com/calendar/v3/freebusy', method: 'post' }, params: params, requiredparams: [], pathparams: [], context: self }; return createapirequest(parameters, callback); } };
there additional learns creating closures inside loops learned on here: javascript closure inside loops – simple practical example. let me know if else runs similar issues. happy share code samples.
Comments
Post a Comment