简体   繁体   中英

app script web app can't access google docs if anonymous

Goal: create an apps script web app that opens a google doc and returns it's name

This functionality stopped working sometime in the last month or so.

  • create apps script project
  • add a doGet
 function doGet(e) { var msg = "none;"; try{ var doc = DocumentApp.openById("1WYNw9IPcsYZXrvK7gOaoOLt7GPiaUhCJ5OEf79h~~~~"); msg = doc.getName(); }catch(e){ msg = e; } return HtmlService.createHtmlOutput(msg); }

Save and follow path for authentication

Publish / Deploy as web app with settings

  • new version because anon unable to use dev version of url
  • execute as me
  • Anyone, even anonymous

Now try it out

  • open the url in authenticated browser
    • not the test url
    • success

Found and opened Intro

open the url in incognito and do not login to any account

Error message

Exception: We're sorry, a server error occurred. Please wait a bit and try again.

Edit: added the line msg = doc.getName();

This works for me even including a new incognito window and another account.

function doGet(e) {
    var msg = "none;";
    try{
      var doc = DocumentApp.openById("docid"); 
      msg = doc.getName();
    }catch(e){
      msg = e;
    }  
    return ContentService.createTextOutput(msg);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM