1

如果用户删除了我的应用所需的任何权限,我想将用户重定向到 oauth 页面。

由于某种原因,当我尝试从 FB.api 回调函数重定向时,以下代码会导致无限循环。有什么想法可以解决这个问题吗?

var perms           = ['publish_actions', 'email', 'user_birthday', 'user_location'],
    permsString     = perms.join(','),
    permissionsUrl  = 'https://www.facebook.com/dialog/oauth';
    permissionsUrl  += '?client_id=' + config.facebook.appId;
    permissionsUrl  += '&redirect_uri=' + encodeURI(canvasUrl);
    permissionsUrl  += '&scope=' + permsString;

    FB.getLoginStatus(function (response) {

        if (response.status === 'connected') {

            FB.api('/me/permissions', function(response) {

                // using underscore here...
                var keys = _.keys(response.data[0]),
                    diff = _.difference(perms, keys);

                // send the user through the auth again if they've removed any of the perms we need
                if (diff.length) {

                    window.location.href = permissionsUrl; // results in an endless redirect loop
                    // window.location.href = 'http://randomwebsite.com'; // does redirect successfully!!!!
                }
            });
        }

    }, true);
4

1 回答 1

0

自从我这样做已经有一段时间了,但是从记忆中我用这样的方法解决了它:

var redirectMe = function (link) {
  window.location.href = link;
};

FB.getLoginStatus(function (response) {
    if (response.status === 'connected') {
        FB.api('/me/permissions', function(response) {
            if (true) {
                redirectMe('http://www.browsehappy.com');
            }
        });
    }
}, true);
于 2013-11-23T14:40:23.947 回答