我正在尝试从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();
}
});
});
};
我做错了什么?
谢谢!
答案 0 :(得分:4)
Google doc文件有一些内部/专有格式,似乎无法直接访问。唯一的选择是通过“exportLinks”集合将Google文档转换为其他一些定义良好的文档类型。