下面是我的應用程序中的一個簡單示例,爲簡單性和可讀性稍作修改。我使用jQuery和jRails(用於Ruby on Rails開發),因此「$(document).ready」。如果您需要更多解釋,請告訴我。
<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>