Drafts Script Reference
    Preparing search index...

    Class GoogleDrive

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

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

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

    // write to file on GoogleDrive
    let 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();
    }
    Index

    Constructors

    Properties

    Methods

    Constructors

    • Create new instance.

      Parameters

      • Optionalidentifier: string

      Returns GoogleDrive

    Properties

    lastError: string

    If a function fails, this property will contain the last error as a string message, otherwise it will be undefined.

    Methods

    • Reads the contents of the file at the with the file name, in the parent folder, as a string. Returns undefined value if the file does not exist or could not be read.

      Parameters

      • fileName: string
      • parent: string

        Name of folder in the root of the Google Drive, or "" for root. FIXME: optional?

      Returns string

    • Write the contents of the file at the path. Returns true if successful, false if the file could not be written successfully. This will override existing files!

      Parameters

      • fileName: string
      • parent: string

        Name of folder in the root of the Google Drive, or "" for root.

      • content: string

        Text to write to file.

      Returns boolean

    • Creates a new GoogleDrive object.

      Parameters

      • Optionalidentifier: string

        used to identify a GoogleDrive account. Typically this can be omitted if you only work with one GoogleDrive account in Drafts.

      Returns GoogleDrive

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.