Regarding this example: https://developers.google.com/google-apps/calendar/quickstart/nodejs
I want to change the listEvents to return a JSON array of the events.
It's currently called like this:
authorize(JSON.parse(content), listEvents);
where "listEvents" is the function passed to the callback:
function authorize(credentials, callback) {
I tried add a return statement to ListEvents and then this:
var jsonEvents = authorize(JSON.parse(content), listEvents);
console.log("Json Events=");
console.log(jsonEvents);
I know it's going async on me, because I get the above console.logs before the console.log output of the listEvents function. I also tried throwing in the "await" word, but no luck.
and I tried setting an extra parameter in in listEvents:
var jsonEvents;
authorize(JSON.parse(content), listEvents(jsonEvents));
console.log("Json Events=");
console.log(jsonEvents);
which resulted in "typeError: callback is not a function".
Update: based on @Tuches answer, I got this to work. Would like to know if it was necessary to expand this far.
authorize(JSON.parse(content), function(token) {
console.log("Got Token");
//console.log(token);
listEvents(token, function(jsonResult) {
console.log("Json Callback Events=");
console.log(jsonResult);
});
});