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 に答える