gpt4 book ai didi

php - Facebook 登录流程返回状态 "unknown"

转载 作者:行者123 更新时间:2023-12-05 08:10:05 29 4
gpt4 key购买 nike

因此,我最近创建了一个可供所有用户使用的 FB,据我所知,该 FB 未处于沙盒模式。我使用了 FB Developers 网站上的文档中提供的示例代码并将其放在本地主机上。 “App Domains”和“Site URL”的设置都是正确的。因此,即使我登录 FB,在登录后,在 Chrome 的 JS 控制台中,它也会显示 statusChangeCallback splash.php:60
对象 {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>

我完全不知道为什么会这样,而且我以前从未遇到过这个问题。

最佳答案

我看了你的代码,

您已经编辑了 js 代码。

使用您可以在下面的链接中找到的代码恢复您当前的 js 代码

https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.1

关于php - Facebook 登录流程返回状态 "unknown",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307669/

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