How do I make Appscript Web App less brittle for use commercially

Viewed 126

I've been playing around with the appscript web app thingy and thought I could use it for commercial purposes among a group of say 15 users. However, I get this sporadically: Sporadic Failure

In the incognito window on the top it works fine. It's logged in as the owner of the app which is me but not really me because I have another account for stuff like this. On the top, is my normal chrome which is logged in as me and as the owner of the account. This is how I set it up settings

And this is the sharing thing on the my projects my projects sharing thing

Finally, it draws from this google sheet which for now only I have access to, so hopefully that means no one else can access the data with permission which hopefully means anyone can open it but no one can get access to my precious data necessary to actually use the sheet unless they have access. Of course, in case I'm wrong I have to obscure the url. Anyway, how do I prevent this "Sorry, unable to open the file at this time" error which happens randomly.

2 Answers

It looks like what you are experiencing is an ongoing issue which many users have reported on Google Issue Tracker here and it stems from multiple accounts being logged in.

I suggest you star ★ the issue above and eventually add a comment saying that you are affected by it.

I use Firebase hosting, which has a free tier and is a Google product, for my website.
Go to your Firebase console when logged into a Google account:

https://console.firebase.google.com/?pli=1

I have minimal content in the Firebase index.html file, and then I load more content after the home page loads by using an AJAX POST call to Apps Script and return the content from Apps Script using the Content Service. I think that Firebase hosting is better than a Google Site. A Firebase hosting site requires some set up and some learning, so it's not as easy as Embedding an Apps Script Web App into a Google Site, but for the long term I think it's a better solution.

function doPost(e) {
try{
  var html;
  
  var fileName = "MyWebsite";

  html = HtmlService.createTemplateFromFile(fileName).evaluate().getContent();
  //Get the html file as a string

  if (!html) {
    html = '<div>There was an error</div>';
  }
  
  return ContentService.createTextOutput(html).setMimeType(ContentService.MimeType.TEXT);
}catch(e) {
  MailApp.sendEmail(Session.getEffectiveUser().getEmail(), "Load Error", e.message +
    "\n\n" + e.stack);
  html = '<div>There was an error</div>';
  return ContentService.createTextOutput(html).setMimeType(ContentService.MimeType.TEXT);
}
}

In your index.html file you need to call the Web App:

window.getWebSiteContent = function() {
  //console.log('getMainContent')

  var payload,url;
  
  url = "Put the Apps Script published Web App URL here";
  //console.log('url: ' + url)

  var xhttp = new XMLHttpRequest();

  xhttp.onreadystatechange = function() {
  //console.log('onreadystatechange')

    if (this.readyState == 4 && this.status == 200) {

      //console.log('this.responseText ' + this.responseText);
      addTheMainContentToTheWebApp(this.responseText);//Run a function that adds the content
    } else if (this.readyState == 4 && this.status !== 200) {
      //console.log('Error',this.status)
    }
  };
  
  xhttp.open("POST",url, true);
  xhttp.setRequestHeader('Content-Type', 'text/plain');

  payload = {data:{"keyName":"Value"}};
  payload = JSON.stringify(payload);
  //console.log('payload: ' + payload)
  xhttp.send(payload);
}

document.addEventListener('DOMContentLoaded', function() {//Runs when the site is loaded
  getWebSiteContent();      
});
Related