0

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.

sbansal
  • 34
  • 5
  • https://developers.google.com/google-apps/calendar/v3/reference/events/insert – Jonathan Portorreal Sep 29 '17 at 04:10
  • That's for just inserting events--how can I create a new calendar? There's no JS example for that in the docs. – sbansal Sep 29 '17 at 06:46
  • I'm not sure what your problem is; you're not using the JS API anyway (which is what those "examples" are about), you're crafting your own requests. That's fine; the documentation lists everything you must include in said request. Is your question simply "how to send JSON via POST"? That would be https://stackoverflow.com/q/24468459/934239 – Xan Sep 29 '17 at 10:36
  • to create a new calender: https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert – Jonathan Portorreal Sep 29 '17 at 11:39

0 Answers0