Activate your free membership today | Log-in

Saturday, January 26th, 2008

Facebook releases JavaScript Client Library

Category: JavaScript, Library, Social Networks

<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:
  1.  
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <title>cross domain receiver page</title>
  4. </head>
  5. <body style="background-color:Green;">
  6.     <script src="http://static.ak.facebook.com/js/api_lib/XdCommReceiver.debug.js" type="text/javascript"></script>
  7.     <script type="text/javascript">
  8.         FB_ReceiverApp$main();
  9.     </script>
  10. </body>
  11. </html>
  12.  

Then, with a few script src's you can talk to Facebook:

JAVASCRIPT:
  1.  
  2. // Create an ApiClient object, passing app’s api key and
  3. // a site relative url to xd_receiver.htm
  4. var api = new FB.ApiClient('<insert_your_app_key_here', '/xd_receiver.htm', null);
  5.        
  6. // require user to login
  7. api.requireLogin(function(exception) {
  8.     window.alert(“Current user id is “ + api.get_session().uid);
  9.  
  10.     // Get friends list 
  11.     api.friends_get(function(result, exception) {
  12.       Debug.dump(result, 'friendsResult from non-batch execution ')
  13.     });       
  14. });
  15.  

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:

  • JavaScript Learning Guide
    This SearchDomino.com guide introduces you to JavaScript in a Notes/Domino environment, explains best practices and pitfalls to avoid and provides...
  • IceSoft betas JavaScript-free Ajax tool
    A beta release of ICEFaces Community Edition, an Ajax development tool for Java coders, was released this week by IceSoft Technologies, Inc. The...
  • Ajax library light as a feather
    Feather Ajax is a new JavaScript library for building rich client user interfaces on Web pages. The script is said to weigh in at less than 1KB and is...
  • Ajax powers Rich Client Faces
    Rich Client Faces is a JavaServerFaces library that provides a component set for building Web applications. RC Faces use Ajax technologies and an...
  • Remove commas from dollar amounts in JavaScript using a split
    Have you ever tried to add up multiple fields with JavaScript, only to find out that the client entered a comma to separate thousands and millions?...

Posted by Dion Almaer at 1:01 am
5 Comments

+++--
3.8 rating from 18 votes

5 Comments »

Comments feed TrackBack URI

This makes developing facebook a bit easier…..but i’m not too thrilled about including my app_key right there in the javascript though.

Comment by Liming — January 26, 2008

FBML? Sry I don´t know that can someone enlighten me?

Comment by Frank Thuerigen — January 27, 2008

right. it looks risky to include app-key as in a javascript file.

Comment by kadnan — January 27, 2008

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#.

Comment by NikhilKothari — January 28, 2008

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!).

Comment by mattk — January 29, 2008

Leave a comment

You must be logged in to post a comment.