gpt4 book ai didi

google-signin - 将谷歌登录集成到静态 html

转载 作者:行者123 更新时间:2023-12-05 07:14:03 27 4
gpt4 key购买 nike

我正在尝试将 google 登录页面集成到静态 html 页面。我所要做的就是,当用户点击 google 登录按钮时,他会获得 google 凭据页面,并且在成功验证后我想在 html 页面中显示基本信息值。这是我的代码。我能够成功登录,但之后我无法看到打印的值。有帮助吗?

<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="<ClientID>">
<title>My Web app</title>
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div id="profileinfo"></div>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
alert("ID: " + profile.getId()); // Don't send this directly to your server!
alert('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());

// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
}
</script>
</body>
</html>

最佳答案

你也没有错误处理,这很难调试。

另一种方法是这样做:

function onSignIn () {

var instance = gapi.auth2.getAuthInstance();

instance.signIn().then((response) => {

var user = response.getBasicProfile();

var data = {
id: user.getId(),
email: user.getEmail(),
name: user.getName(),
// etc
}

console.log(data);

},
err => {
// error handling
console.log(error);
});

}

关于google-signin - 将谷歌登录集成到静态 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60008580/

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