Google Oauth2使用javascript API登录无法使用IE

时间:2013-11-11 09:02:13

标签: javascript internet-explorer google-oauth google-oauth-java-client

我正在使用谷歌oauth2 javascript api来验证我的应用程序的用户。这在Firefox和Chrome中运行良好,但在IE中却没有。我已经尝试过IE 8,9和10但是徒劳无功。我在网上搜索了很多,但dint得到任何解决方案。我已经完成了stackoverflow问题1428548014830177。如果这是谷歌中的现有错误,那么还有其他替代方法吗?我正在尝试下面的代码。 我没有足够的stackoverflow点来评论任何问题,所以问一个新问题。请帮忙。

这是我的代码

 <html>
    <head>
    <script type="text/javascript">       
        window.setTimeout(function() {        
            var po = document.createElement('script'); 
            po.type = 'text/javascript'; po.async = true;        
            po.src = 'https://apis.google.com/js/client:plusone.js';        
            var s = document.getElementsByTagName('script')[0]; 
            s.parentNode.insertBefore(po, s);      
        },1000)(); 

        function signinCallback(authResult) {   
            if (authResult['access_token']) { 
                 document.getElementById('signinButton').setAttribute('style', 'display: none');
            } 
            else if (authResult['error']) {   
                 console.log('Sign-in state: ' + authResult['error']);   
            } 
        }

    </script>
    </head>
    <body>
    <span id="signinButton">
        <span 
        class="g-signin" 
        data-callback="signinCallback" 
        data-clientid="my clinetid" 
        data-cookiepolicy="single_host_origin" 
        data-requestvisibleactions="http://schemas.google.com/AddActivity"     
        data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile">   
        </span> 
    </span> 
    </body>
    </html>

1 个答案:

答案 0 :(得分:1)

试试这个。

<html>
    <head>
    <script type="text/javascript">       
function signinCallback(authResult) {   
            if (authResult['access_token']) { 
                 document.getElementById('signinButton').setAttribute('style', 'display: none');

            } 
            else if (authResult['error']) {   
                 console.log('Sign-in state: ' + authResult['error']);   
            } 
        }

    </script>
    </head>
    <body>
    <span id="signinButton">
        <span 
        class="g-signin" 
        data-callback="signinCallback" 
        data-clientid="my clinetid" 
        data-cookiepolicy="single_host_origin" 
        data-requestvisibleactions="http://schemas.google.com/AddActivity"     
        data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile">   
        </span> 
    </span>
<script type="text/javascript">
  var po = document.createElement('script'); 
  po.type = 'text/javascript'; po.async = true;        
  po.src = 'https://apis.google.com/js/client:plusone.js';        
  var s = document.getElementsByTagName('script')[0]; 
  s.parentNode.insertBefore(po, s);      
</script>
    </body>
    </html>