我在https://console.cloud.google.com/中创建了一个谷歌云项目,然后设置了 Web 客户端,我没有添加 JavaScript 来源(我不知道我是否应该将应用程序脚本 Web 应用程序 URL 放在这里?)从这个 github我得到重定向 URL 将是“https://script.google.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