views:

1622

answers:

1

I have a Facebook app set as an iFrame, pointed to a file on my own server. I followed http://wiki.developers.facebook.com/index.php/JavaScript%5FClient%5FLibrary and the first example, but nothing shows up in the Error Console on Firefox or the textarea. The other non-Facebook stuff in this file works.

What's a simple example using the Facebook JS API to display the name of the person logged in? This is in an iFrame, so I can't use the easy FBML stuff.

+1  A: 

Here's a quick example straight from my application, slightly modified for simplicity and your readability. I use jQuery and jRails (for Ruby on Rails development), hence the "$(document).ready". if you need more explanation, just let me know.

<head>
<script src="/jquery.js" type="text/javascript"></script>
<script src="/jrails.js" type="text/javascript"></script>
<script type="text/javascript">
    function getFriend(friendId){


      // THIS IS WHAT YOU'RE PROBABLY INTERESTED IN

      FB.Facebook.apiClient.fql_query("SELECT name, pic FROM user WHERE uid=" + friendId,
                                    function(rows) {
                                      alert("Hello, " + rows[0].name);
                                    });
    }
    $(document).ready( function(){
      getFriends();
    });

</script>
</head>

<body>

<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

  <script type="text/javascript">
  //<![CDATA[
  FB_RequireFeatures(["XFBML"], function(){ FB.Facebook.init("YOUR_API_KEY", "/xd_receiver.htm"); });
  //]]>
  </script>
</body>
btelles