1

我使用服务器端身份验证设置了“使用Google登录”按钮。一切适用于Chrome,FIrefox,Safari。在IE 11/Edge中,Google登录窗口打开,登录是正确的,但当弹出窗口关闭时什么也没有发生。回调函数永远不会被调用。控制台没有什么 我认为这是Google Sign-in in Internet Explorer/Edge 相同的问题在我的情况,就像在其他线程中,代码是谷歌示例相同。使用谷歌按钮在Internet Explorer 11/Edge中登录

<script type="text/javascript"> 


    function signInCallback(authResult){ 

     if (authResult['code']) { 
      $('#login_social').html(""); 
      setLoading($('#login_social'),'relative'); 
      $.ajax({ 
       url:'gp_ajax_server_login?state=d77e966cf2e830268a4223543a853dd9', 
       type: 'POST', 
       contentType: 'application/octet-stream; charset=utf-8', 
       success: function(response){ 
        if(response == "OK"){ 
          displayLoggedUser(); 
        }else if(response == "CL"){ 
          window.location.href = "/snkt/"; 
        } 
       }, 
       data: authResult['code'], 
       processData: false 
      }); 

     }else{ 
      console.log("GOOGLE SIGN-IN ERROR"); 
     } 
    } 

    function startAndRender(){ 
     gapi.load('auth2', function() { 
      auth2 = gapi.auth2.init(
       {client_id:'XXXXXXXXX.apps.googleusercontent.com'} 
      ); 
     }); 
    } 

</script> 
<script src="https://apis.google.com/js/client:platform.js?onload=startAndRender" async defer></script> 

<center> 
<button id="signinButton" class="g-signin-btn"></button> 
<script> 
    $('#signinButton').click(function(){ 
     auth2.grantOfflineAccess({'redirect_uri':'postmessage'}).then(signInCallback); 
    }); 
</script> 
</center> 
+0

的可能的复制[谷歌登录的Web应用程序无法使用Internet Explorer的工作(http://stackoverflow.com/questions/31494204/google-sign-in-for-web-apps-not-working -with-互联网浏览器) – bummi

回答

2

不幸的是,还没有一个已知的解决方案。经过一番搜索,我发现了许多具有相同问题的帖子。它看起来像一些开发人员试图与谷歌开个案,看看他们是否可以解决这个问题。

Basic Google Sign-In for Websites code not working in Internet Explorer 11

我亲自试过几个不同的变化,包括在网站发布到实时URL(非本地主机)和本地引用platform.js。没有工作。我所描述的问题完全相同。

我会建议试图与谷歌以及微软一起打开一张麻烦票,希望有一个解决方案来自它!

0

我发现了一个解决方法:Google Plus api似乎仍然在IE中工作。 我检测浏览器,并使用IE浏览器使用Plus API,其他浏览器使用Google API。至少在问题解决之前。 我希望这可以帮助别人。

<?php 
//***************** IE 
if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)|| (strpos($_SERVER['HTTP_USER_AGENT'], 'Edge/12') !== false)){ 
?> 
<script type="text/javascript"> 

    (function() { 
     var po = document.createElement('script'); 
     po.type = 'text/javascript'; 
     po.async = true; 
     po.src = 'https://plus.google.com/js/client:plusone.js?onload=start'; 
     var s = document.getElementsByTagName('script')[0]; 
     s.parentNode.insertBefore(po, s); 
    })(); 

    function signInCallback(authResult) { 
     if (authResult['code']) { 

      $('#login_social').html(""); 
      setLoading($('#login_social'),'relative'); 
      $.ajax({ 
       url:'gp_ajax_server_login?state=<?php echo $state?>', 
       type: 'POST', 
       contentType: 'application/octet-stream; charset=utf-8', 
       success: function(response){ 
        if(response == "OK"){ 
         displayLoggedUser(); 
        }else if(response == "CL"){ 
         window.location.href = "/snkt/"; 
        } 
       }, 
       data: authResult['code'], 
       processData: false 
      }); 

     } else if(authResult['error']) { 
      console.log("GOOGLE SIGN-IN ERROR: "+authResult['error']); 
     } 
     } 

</script> 

    <div id="signinButton"> 
     <span class="g-signin" 
     data-scope="https://www.googleapis.com/auth/plus.login email" 
     data-clientid="XXXXXXXXXXXXX.apps.googleusercontent.com" 
     data-redirecturi="postmessage" 
     data-accesstype="offline" 
     data-cookiepolicy="single_host_origin" 
     data-callback="signInCallback" 
     data-width="wide" 
     data-height="tall" 
     data-approvalprompt="auto"> 
     </span> 
    </div> 
<div id="result"></div> 


<?php 
// ********** OTHER BROWSERS 
} else { 
?> 
<script type="text/javascript"> 


    function signInCallback(authResult) { 

    if (authResult['code']) { 
     $('#login_social').html(""); 
     setLoading($('#login_social'),'relative'); 
     $.ajax({ 
      url:'gp_ajax_server_login?state=d77e966cf2e830268a4223543a853dd9', 
      type: 'POST', 
      contentType: 'application/octet-stream; charset=utf-8', 
      success: function(response){ 
       if(response == "OK"){ 
         displayLoggedUser(); 
       }else if(response == "CL"){ 
         window.location.href = "/snkt/"; 
       } 
      }, 
      data: authResult['code'], 
      processData: false 
     }); 

     }else{ 
     console.log("GOOGLE SIGN-IN ERROR"); 
     } 
    } 

    function startAndRender() { 
    gapi.load('auth2', function() { 
     auth2 = gapi.auth2.init(
      {client_id:'XXXXXXXXX.apps.googleusercontent.com'} 
     ); 
    }); 
    } 

</script> 
<script src="https://apis.google.com/js/client:platform.js? onload=startAndRender" async defer></script> 

<center> 
<button id="signinButton" class="g-signin-btn"></button> 
<script> 
    $('#signinButton').click(function() { 
     auth2.grantOfflineAccess({'redirect_uri':'postmessage'}).then(signInCallback); 
}); 
</script> 
</center> 
<?php 
} 
?>