Drafts Scripting Reference

GoogleDrive

GoogleDrive objects can be used to work with files in Google Drive accounts.

Properties

Functions

Class Functions

Examples

// create GoogleDrive object
var drive = GoogleDrive.create();

// setup variables
var fileName = "MyTestFile";
var parent = ""; // root of drive
var content = "text to place in file";

// write to file on GoogleDrive
var success = drive.write(fileName, parent, content);

if (success) { // write worked!
  var driveContent = drive.read(fileName, parent);
  if (driveContent) { // read worked!
    if (driveContent == content) {
      alert("File contents match!");
    }
    else {
      console.log("File did not match");
      context.fail();
    }
  }
  else { // read failed, log error
    console.log(drive.lastError);
    context.fail();
  }
}
else { // write failed, log error
  console.log(drive.lastError);
  context.fail();
}