Java tips, observations, bugs and problems from the world of Spring, Weblogic, Oracle, MySQL and many other technologies...

Friday, 22 June 2012

Facebook and Twitter: Behind the Scenes

In my last blog I created a simple Twitter application that uses the Spring Social Twitter module to access a user’s public time line data. As I said in that blog, the example isn’t particularly complicated and I’ll be adding extra features later. Before I do that I wanted to explain a little about what a Software as a Service (SaaS) provider, such as Facebook and Twitter, is and show something of what the Spring Social API is doing for you.

And the good news is that there’s nothing magical about SaaS services, they’re just a bunch of Web servers that respond to specific HTTP / HTTPS requests with either JSON or XML instead of HTML with the format of those requests published by the SaaS providers on their web sites.

For example, Twitter publishes what it calls their REST API RESOURCES, which you can find at this address:

...which I’ve truncated to save space. Once the Twitter module has the above data, it’ll then parse it into a list of Tweet beans using the Jackson Java JSON-processor and a few other classes. This list of Tweet beans is what your application receives as the return value to its call.

Similarly, Facebook have an API that they call the Graph API; a good name because it allows the caller to access a user’s social graph. Details of the Graph API are available here - although you do need to login to see it:

...the result of which is similarly parsed and returned to your app as a list of POJOs.

However, note the access token, or to give it its full name, the OAuth access token. This is known only by your application and Facebook and is used to grant your application access to your user’s private data. This is what OAuth is all about: your application obtaining an access token so that it can access your user's Facebook, LinkedIn, Sina Weibo or other private SaaS data.

So, how does you app get hold of an access token. It turns out that there are a few hoops to jump through, but more on that next time...