How to get contents of a file? Working with Google Drive API

2,354 views
Skip to first unread message

Joshua Morine

unread,
Jul 18, 2012, 7:52:59 AM7/18/12
to google-api-jav...@googlegroups.com
Hi all,

 I've been working with the Drive API and the Javascript client API for several days now, and have made quite some progress. I can list all files on my drive, create new files, delete, copy, etc...

 My problem is, I cannot for the life of me figure out how to pull the contents of a file(any file). From reading the docs I've discovered that my returned file resource object is supposed to have a
property named "downloadUrl", and from this I should be able to access the file contents.

 None of the file resource objects that are returned to me(via gapi.client.request) have this field/property. Below is the function I am using to get a file.
Can someone please help point me in the right direction? I have to have this demo done by Monday and I've been stuck on this for 2 days....

Client.getFileContent = function getFileContent() {
     gapi.client.load('drive', 'v2', function() {
          var request = gapi.client.request({
               path : '/drive/v2/files/1QmaofXyVqnw6ODXHE5KWlUTcWbA9KkLyb-lBdh_FLUs',
               method : 'GET',
               params : {
                    projection: "FULL"
               }
          });
          request.execute(function(response) {
               console.log(response);   
          });
     });
};


 The returned file resource object has no downloadUrl field/property at all. Also, if I call my functions for performing a file.list operation :

Client.listFiles = function listFiles() {
     gapi.client.load('drive', 'v2', function() {
          var request = gapi.client.request({
               path : '/drive/v2/files',
               method : 'GET'
          });
          request.execute(Client.listCallBack);
     });
};

Client.listCallBack = function listCallBack( response ) {
     //console.log(response.items);
    
     var files = [];

     for( var i=0; i<response.items.length; i++ ) {
          files[i] = {
               id        : response.items[i].id,
               title     : response.items[i].title,
               modDate   : response.items[i].modifiedDate,
               modUser   : response.items[i].lastModifyingUserName,
               testField : response.items[i].embedLink
          };
     }
     UI.displayFiles(files);
};


 None of the file resource objects returned have this downloadUrl property. This includes files/documents/spreadsheets/etc... that I've created programmatically, and directly through the My Drive UI.
Am I doing something wrong in my function calls? Should I be passing and/or requesting other parameters? Or am I looking for a property other than downloadUrl?

 If more information/code is needed please let me know and I will be happy to provide it. Thank you!

 

Brendan

unread,
Jul 19, 2012, 5:52:13 PM7/19/12
to google-api-jav...@googlegroups.com
Hi Joshua,

If you are getting a result, but not seeing an expected field that is likely an issue with the API itself. You could try the Drive API's support page: https://developers.google.com/drive/support

Thanks,
Brendan

Pierre Fauconnier

unread,
Jul 24, 2012, 5:02:32 PM7/24/12
to google-api-jav...@googlegroups.com
On Wednesday, 18 July 2012 13:52:59 UTC+2, Joshua Morine wrote:
 None of the file resource objects returned have this downloadUrl property. This includes files/documents/spreadsheets/etc... that I've created programmatically, and directly through the My Drive UI.
Am I doing something wrong in my function calls? Should I be passing and/or requesting other parameters? Or am I looking for a property other than downloadUrl?

Documentation comes with the following definition:
Short lived download URL for the file. This is only populated for files with content stored in Drive.

Google-files created through "My Drive" like *.gdoc, *.gsheet, have no downloadUrl. See also exportLinks.
Moreover, a file created by an application - without uploading any data - has no downloadUrl. See also Inserting File to Google Drive through API

-- Pierre.
Reply all
Reply to author
Forward
0 new messages