I've been trying for quite a while to download a settings file from a user's google drive for a web app of mine. I'm able to successfully upload a file using javascript, but now I cannot get the google example download code to work to obtain back the contents of the file. Here's the current code. I'm able to obtain the file's metadata.
function downloadFile(file) {
if (file.downloadUrl) {
var accessToken = gapi.auth.getToken().access_token; <-Error
var xhr = new XMLHttpRequest();
xhr.open('GET', file.downloadUrl);
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.onload = function() {
console.log(xhr.responseText);
};
xhr.onerror = function() {
console.log("ERROR");
};
xhr.send();
} else {
console.log("No file.downloadUrl");
}
}
The console error says "Cannot read property 'access_token' of null" which I think it may be because it requires an API key but I'm using a client id to sign people in. Is there a way to do this without using the API key and with the client id?