微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?