DocList WebApp

This will create a simple list of links to files based on the contents of a google folder.   You want to deploy this as a webApp with "run as me" and anyone even anonymous permissions.   I have also found that this only works from an app account. 

Code

//https://script.google.com/macros/s/AKfycbzQdHWc1gZCUNxjHPou5UVHCLfKM2kbanIuDWmEJrrFzmiS643o/exec?folderId=0B1ZDFo1VgBTKQV9SXzJGT0luVFk
//https://script.google.com/macros/s/AKfycbzQdHWc1gZCUNxjHPou5UVHCLfKM2kbanIuDWmEJrrFzmiS643o/dev?folderId=0B1ZDFo1VgBTKQV9SXzJGT0luVFk
function doGet(e) {
  var params = JSON.stringify(e);
  var id = "0B1ZDFo1VgBTKQV9SXzJGT0luVFk";
  var html= "";
  var folder = DriveApp.getFolderById(id);
  var files = folder.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    var fileName = file.getName();
    var fileUrl = file.getUrl();  
    html += "<a href='"+fileUrl+"'>"+fileName+"</a><br>";
  }
  return HtmlService.createHtmlOutput(html);
}


Example:



Modified for sites:
Site gadgets are not able to pickup the parameters so they needed to be built in, when creating a gadget script attatched to a site.

Side gadget code

function doGet(e) {
  var params = JSON.stringify(e);
  var id = "0B1ZDFo1VgBTKQV9SXzJGT0luVFk";
  
  var html= "";
  var folder = DriveApp.getFolderById(id);
  var files = folder.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    var fileName = file.getName();
    var fileUrl = file.getUrl();  
    html += "<a href='"+fileUrl+"'>"+fileName+"</a><br>";
  }
  return HtmlService.createHtmlOutput(html);
}



Example


There is a restriction in Google Apps preventing it from being used in an iFrame, preventing the above solutions from being used in other CMS tools like Wordpress.   To make this work I created a Document app that imported the file list.   This allows for more customization in the look of the list.  To get started open up the below document and click File => Make a copy.  There are limitations, such as not being able to open the links outside the published iFrame.   I suggest your going to file =Publish to Web on your new document and using the embed code in your Wordpress or other.




Comments