首页 文章

Google登录按钮无效

提问于
浏览
0

我想通过此链接将谷歌登录到我的网站:https://developers.google.com/identity/sign-in/web/sign-in

所以我只是设置了一个新的html文件,正是这个代码

<!doctype html>
<html>
<head>
  <meta name="google-signin-client_id" content="917979196053-718dnj8g6c71jkcim2pvqo17mo0b1819.apps.googleusercontent.com">
</head>
<body>
  <div id="my-signin2"></div>
  <script>
    function onSuccess(googleUser) {
      console.log('Logged in as: ' + googleUser.getBasicProfile().getName());
    }
    function onFailure(error) {
      console.log(error);
    }
    function renderButton() {
      gapi.signin2.render('my-signin2', {
        'scope': 'profile email',
        'width': 240,
        'height': 50,
        'longtitle': true,
        'theme': 'dark',
        'onsuccess': onSuccess,
        'onfailure': onFailure
      });
    }
  </script>

  <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>
</html>

代码来自:https://developers.google.com/identity/sign-in/web/build-button

现在的问题是,它根本不起作用 . NOTHING出现在屏幕上,我不知道为什么 . 另一方面,当我在这里尝试它https://jsfiddle.net/wbzax22e/它以某种方式工作 .

这真是荒谬 . 有人可以帮帮我吗?

谢谢!

1 回答

  • 1

    您必须在Web服务器上运行此代码 . 您不能只在本地访问该文件,否则由于cookie策略,代码将会出错 . 如果您希望本地开发服务器查看类似XAMPP的内容或在线查找免费主机 .

相关问题