No "Access-Control-Allow-Origin" header for exportLink

I have a basic javascript snippet to download a public file from Google Drive. I created an API key and configured my domain in the list of allowed sources. I get a typical CORS error when trying to open exportLink as described here https://developers.google.com/drive/web/manage-downloads . The download link works very well when accessed in a browser.

Error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.example.com' is therefore not allowed access.

The code:

// setup api key
gapi.client.setApiKey('myKey');

// load libraries and get file from drive API
...

// download file 

var xhr = new XMLHttpRequest();
xhr.open('GET', file['exportLinks']['text/csv']);
xhr.onload = function() {
    callback(xhr.responseText);
};
xhr.onerror = function() {
    callback(null);
};
xhr.send();
+4
source share
2 answers

, API , exportLinks Google . Google Google . , , , . , , , , .

+3

, PyDrive. Google . , csv :

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

file = drive.CreateFile({'id': 'YOUR ID HERE'})
file.GetContentFile('test.csv', mimetype='text/csv')

client_secrets.json .

-2

All Articles