I'm trying to create a Chrome extension that creates Google Calendars and inserts events into those calendars, but I'm running into a little difficulty using the Google Calendar API since there don't seem to be any concrete examples in JavaScript. Here's what I have so far:
chrome.identity.getAuthToken({ interactive: true }, function(token) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/calendar/v3/users/me/calendarList?access_token=' + token);
x.onload = function() {
alert(x.response);
};
x.send();
});
This gets me as far as successfully getting an access token and using that to retrieve the calendar list of an authorized user--I can verify that that snippet works. So, I should be able to modify this from a GET
request to a POST
or something similar to create a Calendar or insert events into a Calendar, given the Calendar's ID--my question is how can I go about this?
My current structure is a JavaScript content script that injects a button into a web page, processes the page data, and sends that data to a background page (from where the above snippet was taken), which is supposed to get access to a user's calendars and then create a Calendar and insert events into that Calendar using the page data. So far, the content script works perfectly and I can get valid access tokens from the background page, so it's just this last stage of insertion that I'm stuck on.