Google 登录按钮不起作用

Google sign in button not working

我有一个非常基本的问题。我正在尝试通过此 link 集成 google 登录到我的网站: 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

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

这真是荒唐。有人可以帮我吗?

谢谢!

您必须 运行 Web 服务器上的此代码。您不能只在本地访问文件,否则代码会因为 cookie 策略而出错。如果您想要本地开发服务器,请查看 XAMPP 之类的内容或在线查找免费主机。