我在我的网站上使用了谷歌登录:
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
//console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
//console.log('Image URL: ' + profile.getImageUrl());
//console.log('Name: ' + profile.getName());
//console.log('Email: ' + profile.getEmail());
var user_uname = profile.getName();
var user_email = profile.getEmail();
alert(user_uname);
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是一个登录谷歌的按钮:
<div class="g-signin2" data-onsuccess="onSignIn"></div>
Run Code Online (Sandbox Code Playgroud)
我想给用户谷歌登录但问题是每当页面加载时自动调用 onSignIn() 函数。我只想要按钮点击。有谁能够帮助我?