开发者

Facebook iFrame app and JS: how do I get friends through JS Client?

I've gotten the FB JS client library to work on my iframe-based application (cool stuff, I 开发者_开发技巧must say), but now I'd like to retrieve a list of friends from Facebook, in order to populate an AutoComplete field (similar to the friend-selector), but without the additional iframe that would be generated if I used the serverfbml tag.

Anyone know how to retrieve that friend list?


<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript">
  FB_RequireFeatures(['Api'], OnFBFeaturesLoaded);

  function OnFBFeaturesLoaded()
  {
    FB.Facebook.init('<YOUR_API_KEY>', '<XD_RECEIVER_URL>');
    FB.Facebook.apiClient.requireLogin(OnRequireLoginComplete);
  }

  function OnRequireLoginComplete(p_exception)
  {
    var FQL = "SELECT uid FROM user WHERE " +
              "uid IN (SELECT uid2 FROM friend WHERE uid1='<USER_ID_OF_CURRENT_USER>')";

    FB.Facebook.apiClient.fql_query(FQL, function(result, exception)
    {
      if (exception != null)
      {
        // We had some error, do your error handling stuff
      }
      else
      {
        // result is an array containing the friends' user IDs.
        // Have fun.
      }
    });
  }
</script>


SELECT uid 
FROM   user 
WHERE  uid IN (SELECT uid2 
               FROM   friend 
               WHERE  uid1 = *USER_ID_HERE*)


Is the iFrame piece your talking about the Facebook-provided 'share with friends' facility? If so, you'll probably find that a lot easier to use than writing your own. If you write your own, here's what you'll need to do:

If you're strictly on the client side (i.e. JS, not PHP, Java, etc.), make JavaScript calls to the Friends API to get an XML list of friends back. Use JavaScript to parse through the XML and generate a list. You'll have to either write or 'borrow' some code to make that list usable with one or more 'autocomplete' fields. You then need to post that form + fields back to a share API -- many ways to do that, depending on what you're trying to accomplish.

There may already be well-written JS code / plugins that you could use. Do a quicks search and see if you can find something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜