I am writing a JS application to read and write from a Google calendar. I can’t use directly the google api as this is not compatible with my target environment, this is running as a single web page on a local Apache server. For this I am using XmlHttpRequest, this works fine but only when I include an access token ie
xmlReq.setRequestHeader("Authorization", "Bearer " + GOOGLE_ACCESS_TOKEN);
So what I am trying to do is get the access token using an initial XHR I have been following this doc https://developers.google.com/accounts/docs/OAuth2UserAgent This returns an error with the message :
“No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin localhost is therefore not allowed access.”
I have seen this message already related to XHR cross domain request but I can’t see what is the issue here.
Any ideas ?
Here is the code :
this.xmlReq = new XMLHttpRequest();
this.currentUrl='https://accounts.google.com/o/oauth2/auth?';
this.currentUrl += 'response_type=token';
this.currentUrl += '&redirect_uri=http://localhost';
this.currentUrl += '&client_id=999999999999.apps.googleusercontent.com';
this.currentUrl += '&scope=https://www.googleapis.com/auth/calendar';
this.xmlReq.open("GET", this.currentUrl, true);
this.xmlReq.responseType = "auth";
this.xmlReq.send();