谷歌的oauth2 JavaScript客户端在IE 9不工作(Google oauth2 java

2019-07-18 03:12发布

虽然下面的代码工作正常使用Chrome(表明,从用户请求允许弹出窗口,以允许访问地图和位置数据),IE 9将打开弹出的形式,但它是空的; 当调用handleAuthClick方法。 我曾尝试添加一个定时器,但没有效果。 我确保弹出窗口被允许,并检查了弹出网页网址这是在Chrome和IE相同。 有没有人遇到这个问题? 或者有人可以提供一个解决?

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');

        });
    });
}

Answer 1:

什么结束了解决这一问题,从10增加setTimeout的时间到1000的谷歌授权的弹出与正确唱的信息,而不是一个空白屏幕显示。



Answer 2:

这有可能是客户端的Web应用程序和谷歌是通过区域安全封锁之间跨域脚本。

请确保google.com和在脚本运行落入同一个安全区域(Internet区域,典型的。)如果你不知道该网页,看到serverfault#612903 https://serverfault.com/questions/612903 / IE11,如何做-检查-到-这区-A-URL-瀑布

还要确保在Web应用程序和谷歌进行分类的区域配置为允许脚本执行,并确保第三方Cookie访问是允许google.com,因为这是用于检查授权。



Answer 3:

请注意,地图/供稿你正在使用的范围是不推荐使用的谷歌地图数据API,这是不一样的东西的地方API

至于你的实际问题,我重新标记与加API来代替Places API的,因为这是你正在使用在这里。



文章来源: Google oauth2 javascript client not working in IE 9