如果他们删除了我的应用所需的任何权限,我想将用户重定向到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);
答案 0 :(得分: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);