2

我正在尝试从 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();
      }
    });
  });
};

我究竟做错了什么?

谢谢!

4

1 回答 1

4

Google doc 文件有一些内部/专有格式,似乎无法直接访问。唯一的选择是通过“exportLinks”集合将 Google 文档转换为其他一些明确定义的文档类型。

于 2012-08-15T15:52:41.147 回答