Google oauth2 javascript客户端无法在IE 9中运行

时间:2013-01-11 19:40:27

标签: javascript internet-explorer oauth-2.0 google-oauth

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

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

        });
    });
}

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

客户端Web应用程序与Google之间的跨源脚本可能会被区域安全性阻止。

请确保google.com和运行脚本的网页都属于同一安全区域(通常是Internet区域)。如果您不确定,请参阅serverfault#612903 https://serverfault.com/questions/612903/ie11-how-to-check-into-which-zone-a-url-falls

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

答案 2 :(得分:0)

请注意,您使用的地图/ Feed范围适用于已弃用的Google Maps Data API,这与Places API

不同

关于您的实际问题,我正在重新使用Plus API替换Places API,因为这就是您在此处使用的内容。