danthareja / node-google-apps-script

[DEPRECATED - use clasp instead] The easiest way to develop Google Apps Script projects
MIT License
353 stars 70 forks source link

Downloading container bound projects #13

Closed szaboadorian closed 9 years ago

szaboadorian commented 9 years ago

Hi,

I know about the limitation specified in the documentation regarding container bound "scripts" (not projects) https://developers.google.com/apps-script/import-export, but actually the download of the project files of an cotainer bound project is actually working.

The current implementation fails to fetch the project files of such a project because the getProjectTitle() method from download.js fails to find the flle with the id equal to the project id. But ignoring this error (e.g. considering a static or argument-passed project name) would cause the download of the files to work.

function getProjectTitle(fileId, auth) { var deferred = Q.defer(); var drive = google.drive({ version: 'v2', auth: auth }); drive.files.get({ fileId: fileId }, function(err, res) { //if (err) return deferred.reject('Error getting project'); title = null; if(err) { title = "project"; } else { title = res.title; }

console.log('Cloning into \'' + title + '\'...');
deferred.resolve(title);

}); return deferred.promise; }

Furthermore I don't think it should impact the upload functionality, which btw I could not get working so far.

Thanks, Ado

danthareja commented 9 years ago

@szaboadorian can you clarify your distinction between "script" and "project" here?

Am I correct in understanding that you'd like the ability to download the Google Apps file that a given script is bound to? (i.e. a Google Sheet that has an Apps Script project bound to it)

szaboadorian commented 9 years ago

To be more explicit:

I have a Google Sheet with a Project holding several .gs scripts for it (Project is only accessible via Tools -> Script Editor within the Sheet - so it is a "Container Bound" project).

In the https://developers.google.com/apps-script/import-export documentation is stated "Note that the file ID of a project is not the same as the project key. The file ID is the alphanumeric string in the project's URL."

So, this kind of project is not visible directly in Drive, and so we can not get its File ID (from the URL, similar to as you describe in the installation and usage guide of the tool). But still we can find the "Project Key", and calling the "https://script.google.com/feeds/download/export?id=" endpoint with it is actually working (even though I can not find any API specification of this endpoint- is it a deprecated one?). The fact that this is working lead me to think that the Google specs are actually limiting the manipulation of only one file from within a project and not manipulating an entire project (but I might be interpreting wrong because at the end the project is also seen as a file from Drive point of view, and the fact that using the project key is working in the export service is just a "hack" :) )

So considering the above, and running the download script with the Project Key and not the File ID, I notice that the getProjectTitle() function is of course failing (as it uses the Drive API which works with the File ID), but the getProjectFiles() function is succeeding. This is why I was suggesting that with a small adjustment of ignoring the fail of getProjectTitle() for this case (or adding new arguments like projectkey and projectname), could lead to a working version of downloading a container bound project.

Upload I don't think is possible to get working, as it uses the drive API (not the script.google.com API), which needs the FileID not the project key. I am wondering if there is any import endpoint trough the "script.google.com" API :)

Thanks, Ado

danthareja commented 9 years ago

Thanks for the detailed clarification. I didn't know you could download via Project Key, that's really interesting!

I'm not totally comfortable implementing a potentially deprecated (or even worse, completely unknown) endpoint. Without official support or documentation, this workaround could break at any time. Additionally, I'm not sure how useful it is without the upload side.

Really interesting find though. Feel free to fork/clone/push a copy and make the change to satisfy your needs.