Question

I'm using pyfacebook on my app but I'm having problems displaying xfbml For example I have to use iframes to display like buttons or like boxes.

What's strange: 1) On the login page the appears correctly, I just have problems on other pages (once logged in)

2) The FB.init part I use is

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
<script type="text/javascript">FB.init("{{ apikey }}", '/static/xd_receiver.html');

Whereas on the facebook docs the arguments are:

FB.init({
  appId  : 'YOUR APP ID',
  status : true, // check login status
  cookie : true, // enable cookies to allow the server to access the session
  xfbml  : true  // parse XFBML
});

3) When I change the FB.init to the official fb one, application doesn't work anymore. (eg I can't logout using this

<a href="#" onclick="javascript:FB.Connect.logoutAndRedirect('/')">Logout</a>

I'm relatively new to FB stuff, so I'm probably mixing things up, but I just want to display correct fbml on my app without modifying too much the server side.

Was it helpful?

Solution

I think you are confusing Facebook's old javascript API with their new javascript API.

As mentioned on the new API page, use this to do the init:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: 'your app id', status: true, cookie: true,
             xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

For the logout, you would want something like this:

<a href="#" onclick="javascript:FB.logout(function(response) {window.location.href = '/';})">Logout</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top