About this Blog
Hi, I'm Dominiek, co-founder of a stealth startup, former CTO at Smart.fm and owner of Synaptify Consulting. This blog is about Startups, Technology and Hacking. One big re-occurring topic is the convergence of several web technologies that create the so-called Synaptic Web.
-
Previous Articles
In the Past
Additional comments powered by BackType
Actual Contact Finder using the Social Graph API
This week I suddenly realized that one month ago, we implemented XFN on iknow.co.jp – the startup I’m working for. I almost completely forgot about this and I needed some 20%-google-time distraction from my day to day tasks. So I thought about doing a quick search and jacking in a simple friend finder that uses the Social Graph API. A friend finder meaning: you input your SNS-X username and you will get all SNS-X usernames that are your friends on SNS-Y, SNS-Z.
To my amazement I couldn’t find any straightforward pieces of code actually doing this. All I could find was the usual pretty printed JSON outputs. So I rolled up my sleeves and did some Javascript hacking myself.
Click here for a Demo
I wrote a Javascript class that you can easily use to enable a friend-finder on your own SNS site. Basically there are two main parameters:
The code should be fully customizable for your own SNS, feel free to use it however you want: (don’t forget to fetch socialgraph.js)
// callback: function contact_found(username, is_new, on_site_name, on_profile_url) { // a user on this site was found and is a friend on_profile_url // this is also where the is_friend_already? check goes } // callback: function contact_search_status(percentage) { // progress report, might take a while to query everything } // setup regexp for this SNS var site_regexp = new RegExp(/http:\/\/www\.iknow\.co\.jp\/user\/([^\/]+)/); // setup library and pass in callbacks (contact_search_status is optional) var social_graph = new SocialGraph(site_regexp, contact_found, contact_search_status); // recommend for user dominiek social_graph.contacts_for('http://www.iknow.co.jp/user/dominiek');When doing a search, about 8 to 40 calls are done to the SocialGraph API to walk through all the data. That’s one of the reasons why I really love JSON – all of this stuff is done on the client side.
Please note that any profile URL used in gathering friends data has to be referred to or must refer some other XFN relationships. The more ‘me’ and ‘contact’ links, the better the results will be. iknow.co.jp is actually a very good example of this.
Note: a fellow developer (Zev Blut) pointed out to me that instead of fooling around with too many regular expressions it’s good to look into Node Canonicalization