繁体   English   中英

登录谷歌帐户后什么都没有发生

[英]Nothing is happening after i sign in to a google account

<!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 文件。 谷歌登录按钮正在工作,但在我登录后它没有做任何事情。它应该将谷歌登录按钮显示为无,并向我显示登录用户的数据属性。 我也有一些错误:

Function onSignIn 和 SignOut 被定义为机器人未使用

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

$ 使用但未定义

gapi 使用但未定义

已使用但未定义的警报

对于在尝试将 google 登录到您的 web 应用程序时偶然发现此问题的任何人。 如果您在未调用 onSignIn 时遇到此问题:

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

还要确保将您的来源列入白名单 client_id并添加端口(如果它不是 80)

基本上这解决了它,因为我设法将错误定位到数据成功。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM