Google登录按钮无效

时间:2017-07-16 11:55:27

标签: javascript html jsfiddle google-signin

我有一个非常基本的问题。我试图通过以下链接将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

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

这真的很荒谬。有人可以帮帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

您必须在Web服务器上运行此代码。您无法在本地访问该文件,否则代码将因Cookie政策而出错。如果您希望本地开发服务器查看类似XAMPP的内容或在线查找免费主机。