javascript - PHP-SDK for Facebook Connect Generating Error on Logout

Solution:
You need to have thefb-root
DIV tag first, then callFB.init()
and thenFB.logout()
Answer
Solution:
There is afb-root
div on line 54 of the original.
The edited javascript is below; now the page just refreshes constantly.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : '<?php echo json_encode($session); ?>', // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.logout(function(response) {
// user is now logged out
});
FB.login(function(response) {
// user is now logged out
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
Answer
Solution:
Sarfraz is correct, but you also have another issue. Follow your logic here:
FB.logout(function(response) {
// user is now logged out
});
FB.login(function(response) {
// user is now logged out
});
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
You log the user out, then you log the user in, then you subscribe to a login event which reloads the page. Once the page reloads, you're logging them out again, in again, refresh, ad nauseum.
Remember these are asynchronous calls. Any of them can return first. If you really want this logic, then you should write it something like this:
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : '<?php echo json_encode($session); ?>', // don't refetch the session when PHP already has it
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.logout(function(response) {
// user is now logged out
FB.login(function(response) {
// user is now logged out
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
});
});
};
But still, I don't see the point...
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.