Saturday, January 26th, 2008
Facebook releases JavaScript Client Library
<p>Wei Zhu seems to be cooking with gas recently, and has released the JavaScript Client Library for Facebook API, which is a client side JavaScript library that mimics the other language client libraries (PHP, Python, Java, Ruby, etc):An application that uses this client library should be registered as an iframe type. This applies to either iframe Facebook apps that users access through the Facebook web site or apps that users access directly on the app’s own web sites.
The solution uses a cross domain receiver:
-
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<title>cross domain receiver page</title>
-
</head>
-
<body style="background-color:Green;">
-
<script src="http://static.ak.facebook.com/js/api_lib/XdCommReceiver.debug.js" type="text/javascript"></script>
-
<script type="text/javascript">
-
FB_ReceiverApp$main();
-
</script>
-
</body>
-
</html>
-
Then, with a few script src's you can talk to Facebook:
-
-
// Create an ApiClient object, passing app’s api key and
-
// a site relative url to xd_receiver.htm
-
var api = new FB.ApiClient('<insert_your_app_key_here', '/xd_receiver.htm', null);
-
-
// require user to login
-
api.requireLogin(function(exception) {
-
window.alert(“Current user id is “ + api.get_session().uid);
-
-
// Get friends list
-
api.friends_get(function(result, exception) {
-
Debug.dump(result, 'friendsResult from non-batch execution ');
-
});
-
});
-
It is good to see a JavaScript API like this. Now you can stay in JavaScript land and write code that works with OpenSocial, Facebook, and more. NOTE: If you live in FBML? No cigar.
Related Content:











This makes developing facebook a bit easier…..but i’m not too thrilled about including my app_key right there in the javascript though.
FBML? Sry I don´t know that can someone enlighten me?
right. it looks risky to include app-key as in a javascript file.
Actually the app key is pretty much public information. Facebook generates temp secret values as well, so its intended to be secure.
See http://www.nikhilk.net/Facebook-SDK-ScriptSharp.aspx for more. Additionally this is built using Script#.
FBML is the HTML like mark up that Facebook uses for their 3rd Party app programs. It simply adds a few more tools and data access stuff.
And it’s about time Facebook got some kind of useable javascript platform. Their previous were horrible (old ajax model!).