小编Lea*_*ner的帖子

如何仅在单击按钮时将 google 的 getBasicProfile() 调用到 google 登录?

我在我的网站上使用了谷歌登录:

<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() 函数。我只想要按钮点击。有谁能够帮助我?

javascript jquery google-api google-signin

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

google-api ×1

google-signin ×1

javascript ×1

jquery ×1