Problem with facebook javascript sdk
-
I am trying to modify a wordpress theme to add FB login button. (I know it can be done using a plugin, but there are reasons that I want to do it only in the theme)
I am having problem with $session = $facebook->getSession(); This function $facebook->getSession() keeps returning NULL. This is what I have been doing.
1. I can successfully create facebook object. But I am not sure if I am able to successfully load
the facebook library. I am trying to initialize the library using this code (basically using hooks)add_action( ‘wp_footer’, array( ‘WPfbConnect_Logic’, ‘fbconnect_init_scripts’), 1);
add_action(‘admin_footer’, array( ‘WPfbConnect_Logic’, ‘fbconnect_init_scripts’), 1);function fbconnect_init_scripts(){
echo “in fbconnect_init_scripts”
<div id=”fb-root”></div>
<script>
{
alert(“test77”);
window.fbAsyncInit = function() {
alert(“test1”);
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
});
// 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;
//alert(e.src)
document.getElementById(‘fb-root’).appendChild(e);
alert(“test2”)
}());}
</script>
}
endif;Any thoughts, what I am doing wrong. Will greatly appreciate your help. What is the best way to load facebook java script library? Where should this code be put?
The topic ‘Problem with facebook javascript sdk’ is closed to new replies.