I'm using a react-chrome-redux stack for my chrome extension. I've tried the Javascript / Node.js quickstarts from the Calendar API but they don't work.
So now I'm trying to retrieve the oAuth2 token via Chrome Identity API, then making a HTTP request to get my data.
manifest.json
"oauth2": {
"client_id": "CLIENT_ID.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly"
]
},
"key": APP_KEY}
HTTP request
chrome.identity.getAuthToken({ 'interactive': false }, function(token) {
var init = {
'method' : 'GET',
'async' : true,
'headers': {
'Authorization' : 'Bearer ' + token,
'Content-Type': 'application/json'
},
'contentType': 'json'
};
fetch('https://www.googleapis.com/calendar/v3/calendars/public/events', init)
.then((response) => response.json()) // Transform the data into json
.then(function(data) {
console.log(data);
})
})
I manage to get a long string of characters from the oAuth2 token, but when I try to make the HTTP request, I get a 404 status error.
I've looked for a long time on Stack Overflow but most questions were not well answered, and there doesn't seem to be a simple way to use the API from a chrome extension.
I really hope someone can help me out here, thanks!