Google Drive JS - Making a request to export links
-
07-08-2022 - |
Question
I am trying to get the html out of files in drive using the Drive SDK. I am using the picker API and it works nice, I get the fileID of the file I want the HTML from.
However (as it is a native google file) it does not contain a downloadURL so I am using the exportlinks.
When trying to make a request to the export links (to get the html) I get cross domain error :
XMLHttpRequest cannot load ... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin...is therefore not allowed access.
The code I am using for this request is
xhr.open('GET',resp['exportLinks']['text/html']);
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.onload = function() {
copied = 0;
hideLoading(false);
var html = xhr.responseText;
$('#result_html').attr('value',html);
var $name = $('#result_html').find(".title span").val();
var elements = $(html);
var title = $(elements);
var name = elements[0].innerHTML;
if($('#edit-title').val() == ""){
$('#edit-title').val(name);
}
$('#drive_doc_name').append(Drupal.t('Document selected') + " : " + name);
};
xhr.onerror = function() {
console.log("Error getting HTML");
hideLoading(true);
};
xhr.send();
Please help, I know exportLinks do not support cross browser requests but I do not know how to workaround this...any help would be much appreciated.
Best regards, Joao Garin
No correct solution