所以,我最近创建了一个可供所有用户使用的FB,据我所知,它不是沙箱模式。我使用了FB Developers网站上的文档中提供的示例代码,并将其放在localhost上。设置“App Domains”和“Site URL”都是正确的。所以,即使我登录FB,登录后,在Chrome的JS控制台中,它会显示statusChangeCallback splash.php:60
Object {status: "unknown", authResponse: null}
我使用了以下代码
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if(response.status === 'connected') {
testAPI();
} else if(response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Please log ' + 'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId: "I'm not dumb",
//cookie: true,
status: true,
xfbml: true,
oauth: true,
version: 'v2.1'
});
FB.getLoginStatus(function(response) {
alert(response);
if(response.status === 'connected') {
if(response.authResponse != 'undefined') {
window.location = '<?php echo $base_url; ?>register';
}
} else if(response.status === 'not_authorized') {
// it means we have a user but he hasn't granted any permissions to our app
// we're going to redirect him to the permission page
} else {
//the user is not logged in, as you already have a login button you don't have to do nothing
}
});
FB.Event.subscribe('auth.login', function(response) {
window.location = '<?php echo $base_url; ?>register';
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response);
document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response + '!';
});
}
</script>
<fb:login-button scope="" onlogin="checkLoginState();"></fb:login-button>
<div id="status"></div>
我完全不知道为什么会这样,我以前从未遇到过这个问题。
答案 0 :(得分:0)
我查看了你的代码,
您已编辑过js代码。
使用您可在以下链接中找到的代码恢复当前的js代码
https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.1