gpt4 book ai didi

javascript - 我登录 Google 帐户后没有任何反应

转载 作者:行者123 更新时间:2023-12-01 16:25:21 25 4
gpt4 key购买 nike

<!doctype html>
<html>
<head>
<title>Google Sign-In</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<meta name="google-signin-client_id" content="MY_client_id_that_i_replaced_to_post_here.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/script.js"></script>

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

</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 Addres</p>
<p id="email" class="alert alert-danger"></p>
<button onclick="SignOut()" class="btn btn-danger">SignOut</button>
</div>

</body>

</html>
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());
}
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");
});
}

分别是html和javascript文件。谷歌登录按钮正在工作,但在我登录后它没有做任何事情。它应该显示谷歌登录按钮,并向我显示登录用户的数据属性。我也有一些错误:

函数 onSignIn 和 SignOut 被定义为未使用的机器人

在 var profile 和 var auth2 之前缺少“严格使用”

$已使用但未定义

gapi已使用但未定义

已使用警报但未定义

最佳答案

致那些在尝试在您的网络应用程序中实现 Google 登录时偶然发现此问题的人。如果您在未调用 onSignIn 时遇到此问题:

清除浏览器缓存。由于某种原因,它起作用了。

另请确保将 client_id 上的来源列入白名单并添加端口(如果端口不是 80)

基本上这解决了这个问题,因为我设法将错误定位到 data-onsuccess。

关于javascript - 我登录 Google 帐户后没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62159464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com