当我运行此代码时,会弹出登录名,并且我的控制台日志开始无限循环运行。我不确定我是否正确使用了 FB.login() 方法。在用户到达我的应用程序连接的情况下,我想提示权限,如果他们被授予,是否会返回一个“连接”状态,如果它被拒绝,我应该检查和处理?
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
//if connected open permissions dialog
FB.login(function(response) {
//if user grants permissions, make ajax call to pass signed request to php page
if(response.status === 'connected'){
$.ajax({
url : "http://xxxxxxio/bn/s_Request.php",
type : 'POST',
data: {signed_request: response.authResponse.signedRequest},
success : function (result) {
console.log(result);
},
error : function () {
alert("error parsing signed request");
}
});//closes ajax
}else{
//if authorization cancelled, redirect to home page
window.location = "http://spilot.kd.io/bn/index.php";
}//closes else
}, {scope: 'user_location,user_likes'});
testAPI();
} else if (response.status === 'not_authorized') {
// the person is logged into Facebook, but not into the app
FB.login(function(response) {
// handle the response
}, {scope: 'user_location,user_likes'});
} else {
// the person is not logged into Facebook, call the login()
FB.login(function(response) {
// handle the response
}, {scope: 'user_location,user_likes'});
}//closes else
});//closes event subscribe
var testAPI = function() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
};