1

I activated the Advanced Drive Service (Drive API, V2), and I tried to publish to the web a file

I tried the following, but obviously, I miss something (the resource).

function test(){
   var fileId = '1c5fRpKAk2YdUVzCa1LOCqDgTLZmYjsfSvTzR9BSGPYo';
   var revisions = Drive.Revisions.list(fileId);
   var items = revisions.items;
   var revisionId = items[items.length-1].id;
   var resource;
   Drive.Revisions.update( resource , fileId, revisionId).published = true;
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Looking at the documentation "This is only populated and can only be modified for Google Docs." It sounds like this might not apply to spreadsheets. https://developers.google.com/drive/v2/reference/revisions/update – Tom Woodward Nov 08 '16 at 01:12
  • The only thing that I can find that gets a "Resource" is `var resource = Drive.Revisions.get(fileId, revisionId);` – Alan Wells Nov 08 '16 at 01:56
  • Thanks Sandy, I try your piece of code, now there is no error message, but the file is not published. – STTP Smart Triathlon Training Nov 08 '16 at 08:01
  • function test(){ var fileId = '1c5fRpKAk2YdUVzCa1LOCqDgTLZmYjsfSvTzR9BSGPYo'; var revisions = Drive.Revisions.list(fileId); var items = revisions.items; var revisionId = items[items.length-1].id; var resource = Drive.Revisions.get(fileId, revisionId); Drive.Revisions.update( resource , fileId, revisionId).published = true; Drive.Revisions.update( resource , fileId, revisionId).publishAuto = true; } – STTP Smart Triathlon Training Nov 08 '16 at 08:02
  • Please check [Programmatically get a Spreadsheet “Published on the web”](http://stackoverflow.com/questions/13016395/programmatically-get-a-spreadsheet-published-on-the-web) if it can help. You might also need to integrate the OAuth2 flow with the built-in authorization dialog. – Teyam Nov 08 '16 at 15:14

1 Answers1

5

several months later, we got the solution !!

//this function publish to the web the document given by ID (google sheets or docs)
function publishToWeb(){ 
var fileId = 'WqcTq4c3iumeEUSgPMCcM8yKUqycQsrn_w3XeE'; 
var revisions = Drive.Revisions.list(fileId); 
var items = revisions.items; 
var revisionId =items[items.length-1].id; 
var resource = Drive.Revisions.get(fileId, revisionId); 
resource.published = true;
resource.publishAuto = true;
resource.publishedOutsideDomain = true;
Drive.Revisions.update(resource, fileId, revisionId); 
}