Google Drive API failing. Files:get response CORS error

Viewed 453

I have a web application that relies on saving files to Google Drive and later retrieving them from the server. I am using the Google API Javascript Client and using similar code to the Google Drive API example to retrieve the file. I use a request to the Google API get service to retrieve the file metadata and then I use that file's downloadUrl contained in the metadata to request that file through an XmlHttpRequest, retrieving the access token from the Google API.

getContents = function(fileId,callbackFunction) {
    var request = gapi.client.drive.files.get({ fileId : fileId});
    request.execute(function(metadata) {
        if(metadata.downloadUrl) {
            var connection = new haxe.Http(metadata.downloadUrl);
            var accessToken = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse(true).access_token;
            connection.setHeader("Authorization","Bearer " + accessToken);
            connection.async = true;
            connection.onData = function(data) {
                callbackFunction(metadata,haxe.io.Bytes.ofString(data));
            };
            connection.onError = function(error) {
                callbackFunction(metadata,null);
            };
            connection.request(false);
        }
    });
}

As recently as of yesterday, the Google API has stopped working when retrieving files. I can get the file metadata just fine, but when requesting the downloadUrl, it is blocked by the CORS policy because the Google API response does not contain the 'Access-Control-Allow-Origin' header. I have made no changes to the relevant code for a long time, so I am at a loss as to why this suddenly stopped working. Does anyone have any insight as to the source of this problem?

0 Answers
Related