我正在尝试从 javascript 应用程序中获取电子表格文档的内容。但是来自的响应'/drive/v2/files/' + documentId
没有“downloadUrl”属性。
我的代码是:
var apiKey, clientId, documentId, scopes;
documentId = "XXXXXXXXXX";
clientId = 'XXXXXXXXXXXXX.apps.googleusercontent.com';
apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXX';
scopes = 'https://www.googleapis.com/auth/drive';
window.OnLoadCallback = function() {
console.log("google client loaded!");
gapi.client.setApiKey(apiKey);
return window.setTimeout(checkAuth, 1);
};
window.checkAuth = function() {
return gapi.auth.authorize({
client_id: clientId,
scope: scopes,
immediate: true
}, function(e) {
console.log("authorized!");
return gapi.client.request({
'path': '/drive/v2/files/' + documentId,
'method': 'GET',
callback: function(theResponseJS, theResponseTXT) {
var downloadUrl, myToken, myXHR;
console.log(theResponseJS);
console.log(theResponseJS.downloadUrl); //is missing
myToken = gapi.auth.getToken();
myXHR = new XMLHttpRequest();
myXHR.open('GET', theResponseJS.downloadUrl, true);
myXHR.setRequestHeader('Authorization', 'Bearer ' + myToken.access_token);
myXHR.onreadystatechange = function(theProgressEvent) {
if (myXHR.readyState === 4) {
if (myXHR.status === 200) {
return console.log(myXHR.response);
}
}
};
return myXHR.send();
}
});
});
};
我究竟做错了什么?
谢谢!