Google 使用 Apps 脚本项目登录 Web 应用程序 - 错误 400:redirect_uri_mismatch

问题描述

这是我点击登录按钮后得到的。

enter image description here

我在 https://console.cloud.google.com/ 中创建了一个谷歌云项目,然后设置 Web 客户端,我还没有添加 JavaScript 源(我不知道我是否应该将应用程序脚本 Web 应用程序 URL 放在这里?)并且从 this github 我得到的重定向 URL 将是“https://script.google.js”。 com/macros/d/{script_id}/usercallback”。 script_id 是我的应用程序脚本 ID。

设置 Google Web 客户端设置以使用 Google 登录到使用应用程序脚本项目创建的 Web 应用程序的正确方法是什么?

我肯定错过了很多东西。

JavaScript 文件 JS003.html 文件有如下代码

<script>
function onSignIn(googleUser)
{
  var profile = googleUser.getBasicProfile();
  $(".g-signin2").css("display","none");
  $(".data").css("display","block");
  $("#pic").attr('src',profile.getimageUrl());
  $("#email").text(profile.getEmail());

  logInfo(profile);

}

function SignOut()
{
  var auth2= gapi.auth2.getAuthInstance();
  auth2.signOut().then(function(){
    alert("You have been successfully signed out");
    $(".g-signin2").css("display","block");
    $(".data").css("display","none");
  });
}

function logInfo(profile){
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getimageUrl());
  console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}
  </script

我的 GS 代码文件 Code.gs 有以下功能

function doGet(){
  var index = "Index003";
  return HtmlService.createTemplateFromFile(index)
  .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

和 HTML 文件 Index003.html 如下:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <Meta name="google-signin-client_id" content="865560649437-1mi0ebrq8rb4rq9ejrrh3eouiics60f9.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
  </head>
  <body>
    <div class="g-signin2" data-onsuccess="onSignIn"></div>
    <div class="data">
      <p> Profile Details</p>
      <img id="pic" class="img-circle" width="100" height="100"/>
      <p>Email Address</p>
      <p id="email" class="alert alert-danger"></p>
      <button onclick="signOut()" class="btn btn-danger"></button>
    </div>

   <!-- Script -->
   <!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<?!= include('JS003') ?>
  </body>
</html>

CSS 文件 CSS003.html

<style>
.g-signin2{
  margin-left:500px;
  margin-top:200px;
}

  </style

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...