New Google Sites – Embed HTML, Javascript and Google Spreadsheets

Question:

I'm trying to use the object "Embed" from the new Google Sites I select the option "Embed Code" and put the code below and when executed the following error message appears: "ReferenceError: SpreadsheetApp is not defined" Does anyone know of any alternative that will solve this problem ?? Thanks

<head>
 <script>
   function funcaoLogar(){
     try{
      var planilha = SpreadsheetApp.openById('1y-hmm2qSJGzZ1M8kHD-ZF-....');
      var pasta = planilha.getSheetByName("DADOS");

      var pLogin = pasta.getRange(1, 1).getValue();
      var pSenha = pasta.getRange(2, 1).getValue();
     } catch (erro) {
          document.getElementById('texto').innerHTML = erro;
        }

     var login = document.getElementById('fLogin').value;
     var senha = document.getElementById('fSenha').value;

     if(login == pLoguin && senha == pSenha){
         window.open('https://sites.google.com/view/perfil...';  
        }else {document.getElementById('texto').innerHTML = "Login ou Senha errada";} 
  }
 </script>
</head>

<body>
 <p>Login: <input id="fLogin" type="text" value="">
 <p>Senha: <input type="password" id="fSenha" type="text" value="">
 <p><button type="button" onclick="funcaoLogar()">Logar</button>
 <p id="texto">
</body>

Answer:

Trying to simplify the problem in Google App Script I created the file Code.gs with the code below:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('arquivoHTML');
}

function mostrarTexto(){
    //escreva aqui o seu código Google Script;
    return "Deu certo!!!!";
}

I created the HTML.html file with the code below

<!DOCTYPE html>
<html>
<body>
    <script>
      function funcaoScript(){
          google.script.run
          .withSuccessHandler(function(retornoFuncao){
                document.getElementById('resultado').innerHTML = retornoFuncao;
            })
          .mostrarTexto();
      }
    </script>
    <button onclick="funcaoScript()">Mostrar Resultado</button>
    <p id="resultado"></p>
</body>
</html>

I activated the API: Google Classroom API

when I tested using the Publish >> Deploy as web application menu… it worked. But when I tried to embed in google sites it appeared "undefined"

I also tried to embed the html code on google sites itself and nothing happened.

Maybe it's a light for the solution to the problem.

Scroll to Top