Google登录按钮无法在本地Chrome上运行

时间:2017-06-22 04:00:26

标签: google-chrome

我尝试添加Google登录按钮,但它无法在Chrome上运行。相同的代码完全适用于Safari。

我只是复制并粘贴了以下示例自定义按钮代码:

https://developers.google.com/identity/sign-in/web/build-button

<html>
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
  <script src="https://apis.google.com/js/api:client.js"></script>
  <script>
  var googleUser = {};
  var startApp = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: 'YOUR_CLIENT_ID.apps.googleusercontent.com',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'
      });
      attachSignin(document.getElementById('customBtn'));
    });
  };

  function attachSignin(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {
          document.getElementById('name').innerText = "Signed in: " +
              googleUser.getBasicProfile().getName();
        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
        });
  }



</script>
  <style type="text/css">
     ... 
  </style>
  </head>
  <body>
  <!-- In the callback, you would hide the gSignInWrapper element on a
  successful sign in -->
  <div id="gSignInWrapper">
    <span class="label">Sign in with:</span>
    <div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>
      <span class="buttonText">Google</span>
    </div>
  </div>
  <div id="name"></div>
  <script>startApp();</script>
</body>
</html>

我已将YOUR_CLIENT_ID更改为我的应用ID,请确保Chrome不会阻止第三方Cookie。

在Chrome(版本58.0)上,当我点击按钮时,它会显示{&#34;错误&#34;:&#34; popup_closed_by_user&#34;}

相同的代码适用于Safari。该应用程序在Mac OS上本地运行。

有没有人有解决方案或者它是一个错误?

0 个答案:

没有答案