Displaying articles with tag facebook

A quick facebook connect guide

Posted by PunNeng, Tue Feb 17 01:32:00 UTC 2009

Here is a quick todo
http://wiki.developers.facebook.com/index.php/TryingOutFacebook_Connect

There is a tricky part. It is when you are logged in, you have to make the page reload automatically.
Fortunately, there is a javascript helper
http://www.somethingtoputhere.com/therunaround/fbconnect.js

Usage:

put these codes below to your page, it will render the link to log in.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
<script src="/javascripts/fbconnect.js" type="text/javascript"></script>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<a href="#" onclick="FB.Connect.requireSession(); return false;" >
  <!-- this can be a text link or image tag -->
  <input type="image" value="facebook" src="/images/buttons/btn_facebook.gif"  />
</a>
<script type="text/javascript"> FB.init("YOUR_APP_KEY", "xd_receiver.htm"); </script>

<script type="text/javascript">
  FB.Connect.ifUserConnected(function(){
   // will be invoked if user is connected and refresh the site to the callback url(explain below)
   window.onload = function() { facebook_onload(true); };
  },
  function(){
   // will be invoked if user is not connected
   window.onload = function() { facebook_onload(false); };
  }
  )
</script>

Changing the callback url:

in fbconnect.js, there are codes:

  1
  2
  3
function refresh_page() {
  window.location = 'index.php';
}

index.php is needed to be changed to the callback path.
This method will be called after the user is connected.

Getting the facebook id:

When it's redirected to the url above, the facebook id or the user details should be in the session of the site. You need to echo the session to see what keys are in the session.

0 comments | Filed Under: General | Tags: facebook

codegent: we're hiring