Title: Problem with facebook javascript sdk
Last modified: August 19, 2016

---

# Problem with facebook javascript sdk

 *  [azubair](https://wordpress.org/support/users/azubair/)
 * (@azubair)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/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?

Viewing 1 replies (of 1 total)

 *  Thread Starter [azubair](https://wordpress.org/support/users/azubair/)
 * (@azubair)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/problem-with-facebook-javascript-sdk/#post-1861710)
 * Actually hook function is getting invoked, but getsession is still NULL. Will
   really appreciate your help.

Viewing 1 replies (of 1 total)

The topic ‘Problem with facebook javascript sdk’ is closed to new replies.

## Tags

 * [facebook wordpress](https://wordpress.org/support/topic-tag/facebook-wordpress/)

 * 1 reply
 * 1 participant
 * Last reply from: [azubair](https://wordpress.org/support/users/azubair/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/problem-with-facebook-javascript-sdk/#post-1861710)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
