I'm brand new to Google API of any kind and relatively new to code in general. I'm trying to make a website that will allow me to select multiple days from a list of checkboxes and create Google calendar events on those days for me.
I'm using an ASP.net webpage for display and checkbox logic and sending the checkbox results to Javascript as JSON. Then handling the JSON and google calendar stuff in Javascript.
Just by copying the boilerplate code from some examples, I'm able to get authenticated through Google and successfully add an event to my calendar with hardcoded event details. The problem begins when I try to populate the event details with variables rather than hardcoded details.
I believe I'm real close on getting this working and there's just some small formatting issue keeping it from working.
This works with the hardcoded details in "var resource"
function makeApiCall3() {
for (var i = 0; i < arrayOfEvents.length; i++)
{
var t1 = "{\"summary\":\"" + arrayOfEvents[i].summary + "\", \"start\":" + JSON.stringify(arrayOfEvents[i].start) + ", \"end\":" + JSON.stringify(arrayOfEvents[i].end) + "}";
gapi.client.load('calendar', 'v3', function () {
var resource = {
"summary": "Appointment",
"location": "Somewhere",
"start": {
"dateTime": "2017-05-29T10:00:00.000-07:00"
},
"end": {
"dateTime": "2017-05-29T10:00:00.000-07:00"
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': resource
});
request.execute(function (resp) {
console.log(resp);
});
alert(t1);
});
}
alert("End of Calendar Call");
}
This does not work when I try to replace the content of "resource" with my created details "t1".
function makeApiCall3() {
for (var i = 0; i < arrayOfEvents.length; i++)
{
var t1 = "\"summary\":\"" + arrayOfEvents[i].summary + "\", \"start\":" + JSON.stringify(arrayOfEvents[i].start) + ", \"end\":" + JSON.stringify(arrayOfEvents[i].end);
gapi.client.load('calendar', 'v3', function () {
var resource = { t1
// "summary": "Appointment",
// "location": "Somewhere",
// "start": {
// "dateTime": "2017-05-29T10:00:00.000-07:00"
// },
// "end": {
// "dateTime": "2017-05-29T10:00:00.000-07:00"
// }
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': resource
});
request.execute(function (resp) {
console.log(resp);
});
alert(t1);
});
}
alert("End of Calendar Call");
}
This does not work either where I just replace the "var request" "resource" portion to "t1".
function makeApiCall3() {
for (var i = 0; i < arrayOfEvents.length; i++)
{
var t1 = "{\"summary\":\"" + arrayOfEvents[i].summary + "\", \"start\":" + JSON.stringify(arrayOfEvents[i].start) + ", \"end\":" + JSON.stringify(arrayOfEvents[i].end) + "}";
gapi.client.load('calendar', 'v3', function () {
var resource = {
"summary": "Appointment",
"location": "Somewhere",
"start": {
"dateTime": "2017-05-29T10:00:00.000-07:00"
},
"end": {
"dateTime": "2017-05-29T10:00:00.000-07:00"
}
};
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': t1
});
request.execute(function (resp) {
console.log(resp);
});
alert(t1);
});
}
alert("End of Calendar Call");
}
For debugging I've been making alerts and the t1 alert result looks as if I've formatted the data exactly as the boilerplate code was, yet it isn't working. (Photo here->) alert(t1) result
I tried the batch method discussed here but couldn't make that work either. Google Calendar javascript api - Add multiple events
Thanks for any help.