gpt4 book ai didi

javascript - Facebook oauth javascript 重定向导致无限循环

转载 作者:行者123 更新时间:2023-11-28 09:55:31 25 4
gpt4 key购买 nike

如果用户已删除我的应用所需的任何权限,我希望将用户重定向到 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);

最佳答案

我已经有一段时间没有这样做了,但根据内存,我用这样的方法解决了它:

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

关于javascript - Facebook oauth javascript 重定向导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10113178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com