views:

2410

answers:

2

The snippet below is supposed to get a friends list from a user's Facebook profile into my app:

<script 
  type="text/javascript"
  src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"&gt;
</script> 
<script type="text/javascript">
FB_RequireFeatures(
    ["XFBML"],
    function() {
      FB.Facebook.init("xxxxxxxx","xd_receiver.htm"); 
      FB.Facebook.get_sessionState().waitUntilReady(
        function() {
          FB.Facebook.apiClient.friends_get(
            null,
            function(result,ex){window.alert("friends list :" + result);}
          );
        }
      );
    }
);
</script>

Instead of name of my friends I get some integer. I couldn't guess why. It would be nice to know why my approach doesnt work.

+2  A: 

Your approach does work, but as Documented on the Facebook Developer Wiki, the function FB.ApiClient.Friends_get which you call doesn't return the names of friends, it returns an array of their user IDs which are large (often bigger than integer) number values. You will need to use an additional function, FB.ApiClient.users_getInfo, in order to return the name(s) of users. You also don't need to call FB.Facebook.ApiClient, you can bypass the Facebook object using FB.ApiClient directly.

Here is an example (untested, but should give you the idea):

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"&gt;&lt;/script&gt; 
<script type="text/javascript">
  FB_RequireFeatures(
    ["XFBML"],
    function() {
      FB.Facebook.init("xxxxxxxx","xd_receiver.htm"); 
      FB.Facebook.get_sessionState().waitUntilReady(
        function() {
          FB.ApiClient.friends_get(
            null,
            function(result,ex) {
              FB.ApiClient.users_getInfo(result, 'name',
                function(friendNames, exec) {
                  window.alert("first name in friends list: " + friendsNames[0]);
                }
              )
            }
          );
        }
      );
    }
  );
</script>
Dustin Fineout
Just wondering if this worked for you. Would be nice of you to maybe post a response, vote... something...
Dustin Fineout
A: 

I believe you have to do:

FB.ApiClient.friends_get(
            new Array(),

Which I saw on the developer site.