title: Google Apps Script PERMISSION_DENIED with sheets addon
body: <p>I tried to implement a simple "Multi selector sidebar" extension based on <a href="https://docs.google.com/spreadsheets/d/1cam1LNJgvWVDx_gmEVmPzuTYaITmsQWhZ7tlcHwAmCY/copy" rel="noreferrer">THIS SHEET</a> which I found in this <a href="https://support.google.com/docs/thread/1993362?hl=en" rel="noreferrer">Google support thread</a></p>
  
  <p>When I copy the sheet it works fine but when I try to put the exact same code in my real sheet, it doesn't work anymore.
  It throws an error when I try to access the GA function from within the template.</p>
  
  <p>I have created a simplified test project which also fails to work for me.</p>
  
  <p><strong>To reproduce the error:</strong></p>
  
  <ol>
  <li>Create a new Spreadsheet at <a href="https://docs.google.com/spreadsheets/" rel="noreferrer">https://docs.google.com/spreadsheets/</a></li>
  <li>Create a second sheet (tab  bottom left) and name it CATEGORIES</li>
  <li>Fill in a few fields in the first column. Content doesn't matter
  <a href="https://i.stack.imgur.com/FrCtR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FrCtR.png" alt="categories"></a></li>
  <li>Got to Tools -> Script editor</li>
  </ol>
  
  <p>In the "code.gs" enter</p>
  
  <pre><code>function doGet() {
    var html = HtmlService.createHtmlOutputFromFile('Index')
        .setTitle('Multiple selector')
        .setWidth(300);
    SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
        .showSidebar(html);
  }
  
  function onOpen(e) {
      SpreadsheetApp.getUi().createMenu('Index')
          .addItem('Show Sidebar', 'doGet')
          .addToUi();
          doGet();
  }
  
  function getOptions() {
    var validation = {
      sheet: 'CATEGORIES',
      range: 'A2:A'
  }
  
    Logger.log("running getOptions");
    Logger.log(SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues());
      return SpreadsheetApp.getActive().getSheetByName(validation.sheet).getRange(validation.range).getDisplayValues()
          .filter(String)
          .reduce(function(a, b) {
              return a.concat(b)
          })
  }
  </code></pre>
  
  <p>And create a second file (HTML file) called Index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;base target="_top"&gt;
      &lt;script&gt;
        function onFailure(error) {
          var div = document.getElementById('output');
          div.innerHTML = "ERROR: " + error.message;
        }
  
        google.script.run.withFailureHandler(onFailure)
            .getOptions();
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="output"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RYKCD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RYKCD.png" alt="Testproject with the code"></a></p>
  
  <ol start="6">
  <li>Save the project</li>
  <li>Click Run-> Run function -> "onOpen" (on first run you'll probably need to authorize the application)</li>
  </ol>
  
  <p>Now in the sheet there should be a sidebar which opens with an error for me <code>PERMISSION_DENIED</code></p>
  
  <p><a href="https://i.stack.imgur.com/un7XA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/un7XA.png" alt="enter image description here"></a></p>
  
  <p>Even when I select a project at Resources -> Cloud platform project it won't work.</p>
  
  <p>Oddly enough if I use the original linked (working) spreadsheet and change something in the code, it won't work anymore for me.</p>
  
  <p>Things I know by now:
  - It doesn't work with my gmail or google apps account
  - For other people using the same document it works
  - Still doesn't work if I disable Adblocker
  - Doesn't work if I access the sheet from incognito mode
  - It does work if I use Firefox instead of Chrome</p>
  
  <p><a href="https://i.stack.imgur.com/9ZoCF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9ZoCF.png" alt="Console log from the browser"></a></p>
  
  <p>What am I missing?</p>