Google Drive API Export GAS File Version


I am currently trying to bring some order to our Google App Script files and develop an HTMLService application that finds and parses GAS files in Google Drive and generates API documentation based on jsdoc style comments.

I have WebApp functionality and I can fetch all the data I need and parse the comments, but by default it will export the contents of the current GAS file, whether posted or not.

What I would like to do is output the content of the last saved version, not the current dev content, is there a way to specify the version to export?

I am using URLFetch()

to get content like below:

var params = {
    headers:{
      'Accept':'application/vnd.google-apps.script+json', 
      'Authorization':'Bearer '+ ScriptApp.getOAuthToken()
    }, 
    method:'get'
  };
  
  var fileDrive = Drive.Files.get(fileId);
  var link = JSON.parse(fileDrive)['exportLinks']['application/vnd.google-apps.script+json'];
  var fetched = UrlFetchApp.fetch(link, params);
  return { meta: fileDrive, source: JSON.parse(fetched.getContentText()) };
      

Run codeHide result


Any help would be appreciated, thanks!

+3


source to share


1 answer


Based on this documentation , each change is referred to as a "Revision" and access to revisions is provided through the Revisions resource. You can programmatically save new versions of a file or request version history as described in Link to versions .

Listing versions



The following example shows how to list the versions for a given file. Please note that some of the revision properties are only available for certain file types. For example, G Suite app files do not take up space in Google Drive and thus return the file size 0

.

function listRevisions(fileId) {
  var revisions = Drive.Revisions.list(fileId);
  if (revisions.items && revisions.items.length > 0) {
    for (var i = 0; i < revisions.items.length; i++) {
      var revision = revisions.items[i];
      var date = new Date(revision.modifiedDate);
      Logger.log('Date: %s, File size (bytes): %s', date.toLocaleString(),
          revision.fileSize);
    }
  } else {
    Logger.log('No revisions found.');
  }
}

      

Hope this helps!

0


source







All Articles