Google oauth2 javascript 客户端无法在 IE 9 中运行 [英] Google oauth2 javascript client not working in IE 9

查看:22
本文介绍了Google oauth2 javascript 客户端无法在 IE 9 中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然下面的代码在使用 Chrome 时可以正常工作(显示一个弹出窗口,请求用户允许访问地图和地点数据),IE 9 会打开弹出窗体,但它是空的;调用 handleAuthClick 方法时.我曾尝试添加 setTimeouts 但没有效果.我确保允许弹出窗口,并检查了 Chrome 和 IE 中相同的弹出页面 url.有没有人遇到过这个问题?或者有人可以提供解决方法吗?

Although the following code works correctly using Chrome (shows a popup that requests permission from the user to allow access to map and places data), IE 9 opens the popup form, but it is empty; when calling handleAuthClick method. I have tried adding setTimeouts but without effect. I ensured popups are allowed, and checked the popup page urls which are identical in Chrome and IE. Has anyone encountered this problem? Or can someone offer a work-around?

var clientId = '############.apps.googleusercontent.com';
var apiKey = '#A#A#A#A##';
var scopes = 'https://www.googleapis.com/auth/plus.me';

function handleClientLoad() {
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth, 1);
}

function checkAuth() {
    gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: true }, handleAuthResult);
}

function handleAuthResult(authResult) {
    if (authResult && !authResult.error) {
        makeApiCall();
    } else {
    }
}

function handleAuthClick(event) {
    try {
        window.setTimeout(function () {
            gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: false }, handleAuthResult);
        }, 10);
    } catch (e) { alert(e.message); }
}
function makeApiCall() {
    gapi.client.load('plus', 'v1', function () {
        var request = gapi.client.plus.people.get({
            'userId': 'me'
        });
        request.execute(function (resp) {
            $(".google-signin").find("img").attr('src', resp.image.url).css('height', '32').css('width', '32');
            $("#login-msg").text('Welcome: ' + resp.displayName);
            $("img.vote").css('visibility', 'visible');

        });
    });
}

推荐答案

最终解决此问题的是将 setTimeout 持续时间从 10 增加到 1000.Google 授权弹出窗口显示正确的登录信息,而不是比一个空白屏幕.

What ending up solving this issue was increasing the setTimeout duration to 1000 from 10. The Google authorization pop-up was displayed with the correct sing-in information, rather than a blank screen.

这篇关于Google oauth2 javascript 客户端无法在 IE 9 中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆