如何在网站上集成Google登录?

时间:2018-12-30 14:21:35

标签: javascript html server google-signin

我想在我的网站上使用Google登录集成,所以我关注了this docthis code 。 不幸的是,这行不通,出现一个弹出窗口,登录我,但是通过执行console.log()所需的信息未出现在控制台中。 这是我的整个代码:

<html lang="en">
  <head>
    <meta name="google-signin-scope" content="profile email">
    <meta name="google-signin-client_id" content="myclientid.apps.googleusercontent.com">
    <script src="https://apis.google.com/js/platform.js" async defer></script>
  </head>
  <body>
    <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();
        document.write('ID: ' + profile.getId()); // Don't send this directly to your server!
        console.log('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;
        document.write("ID Token: " + id_token);
      }
    </script>

    <script>
    document.write('Hello !');
    </script>
  </body>
</html>
感谢您的帮助

编辑:该功能在Edge上有效,但在Google Chrome上无效。this is the error I get

已解决,我删除了所有现有的信用,并创建了一个新的信用。这行得通。

0 个答案:

没有答案
相关问题