Search code examples
drivegoogle-app-maker

Appmaker Preview works, but deployed webapp hangs


Hoping anyone can help with this. I have an Appmaker app on google EAP that uses the drive picker widget to get a file, then unshare that file.

The preview works great, but when I publish the app, it hangs for some reason. It's deployed to run as user (required since I'm using drive picker), and I don't see an obvious security issue, since I've listed myself as admin.

The client side of the app works with no problems. It then sends the file id to the server script successfully. The server script is able to log the file id. But when I invoke DriveApp, it hangs and times out (no specific error thrown - "We're sorry, a server error occurred. Please wait a bit and try again.").

The line it hangs on is this:

var file = DriveApp.getFilesByName('upcoming stuff092017').next();

But, I've tried other lines as well, like using getFileById(''), createFile('',''), etc.

Not sure what's happening - anybody got ideas?


UPDATE - oddly, the problem seems to be specifically with DriveApp. I added a line in the server script using GmailApp.sendEmail('','',''), and the e-mail sent ... then when the script reached the DriveApp command, it hung and failed again.


Solution

  • // this line works fine
    var iterator = DriveApp.getFilesByName('test');
    
    // App Script freezes both on 'hasNext' and 'next' method calls
    if (iterator.hasNext()) {
      iterator.next();
    } else {
    } 
    

    It is known issue and it is already reported here:

    https://issuetracker.google.com/issues/63946936

    Workaround

    Use advanced Drive API

    enter image description here

    // Server script usage
    var result = Drive.Files.list({ q: 'title = "tmp.js"' });
    
    console.log(result.items.length);
    

    Full advance Drive API reference:

    https://developers.google.com/drive/v2/reference/