Google + HTML登录无法使用IE或Firefox

时间:2014-03-01 22:34:32

标签: google-api google-oauth google-authentication

我正在开发一个通过Google + API使用客户端身份验证的网络应用。我使用了Google的一个修改示例,该示例使用带有应用信息的HTML元素和一些Javascript来处理响应。在Chrome中,一切都很好,但在IE 9+和Fierfox中,我无法启动身份验证。

HTML:

<div id="signin-button" class="hide">
    <div class="g-signin"
         data-callback="loginFinishedCallback"
         data-clientid="{my client id}"
         data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read"
         data-cookiepolicy="single_host_origin"
    >
</div>

使用Javascript:

<script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"></script>
<script type="text/javascript">

        var profile, email;

        function loginFinishedCallback(authResult) {
            if (authResult) {
                if (authResult['error'] == undefined){
                    gapi.client.load('plus','v1', loadProfile);  // Trigger request to get the email address.
                } else {
                    console.log('An error occurred');
                    $( "#signin-button" ).removeClass( "hide" ).addClass( "show" );
                }
            } else {
                console.log('Empty authResult');  // Something went wrong
                $( "#signin-button" ).removeClass( "hide" ).addClass( "show" );
            }
        }

        /**
         * Uses the JavaScript API to request the user's profile, which includes
         * their basic information.
         */
        function loadProfile(){
            var request = gapi.client.plus.people.get( {'userId' : 'me'} );
            request.execute(loadProfileCallback);
        }

        function loadProfileCallback(obj) {
            profile = obj;
            email = obj['emails'].filter(function(v) {
                return v.type === 'account'; // Filter out the primary email
            })[0].value; // get the email from the filtered results, should always be defined.
            displayProfile(profile);
        }

        /**
         * Display the user's basic profile information from the profile object.
         */
        function displayProfile(profile){...}
    </script>

我应该提一下,当页面加载到Firefox,IE或Chrome时,控制台上没有任何错误。

0 个答案:

没有答案