user1597575
user1597575

Reputation:

Missing 'downloadUrl' parameter when requesting file meta-data from Google Drive

I'm trying to fetch the content of a spreadsheet document from a javascript application. But the response from '/drive/v2/files/' + documentId has no 'downloadUrl' property.

My code is:

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();
      }
    });
  });
};

What am I doing wrong?

Thank you!

Upvotes: 2

Views: 673

Answers (1)

Brad Tofel
Brad Tofel

Reputation: 449

Google doc files have some internal/proprietary format, which doesn't seem to be accessible directly. The only option is to convert the Google doc to some other well defined document type via the "exportLinks" collection.

Upvotes: 4

Related Questions