Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News First Spring Social Milestone to Integrate with Twitter, Facebook, LinkedIn and Tripit

First Spring Social Milestone to Integrate with Twitter, Facebook, LinkedIn and Tripit

Leia em Português

This item in japanese

Last week SpringSource released a first milestone for Spring Social, a Spring-based template for accessing social networking sites from within Java programs.

This first milestone includes templates for Twitter, Facebook, LinkedIn and Tripit. Rather than exposing generic, URL-based APIs, the Spring Social APIs are specifically designed for each social networking site and make integrating with those sites relatively straight forward. Each template is, in turn, built on top of Spring's RestTemplate, which is a generic template for accessing any REST-based web service.

To use Spring Social, developers:

  1. Manually set up a one-time developer account with the target social networking site.
  2. Programmatically request an OAuth token from the target social networking site for each new user.
  3. Instantiate the right Spring Source template (ie. TwitterTemplate), passing in their developer keys as well as the OAuth key for the current user.
  4. Call whatever method they like on the Spring Source template object, much like calling methods on a JdbcTemplate.


Once authorized, the application code required to manipulate a given social networking site is nearly trivial, as in the below example to get a user's LinkedIn connections:

LinkedInTemplate template = new LinkedInTemplate(developerApiKey, developerSecret, oauthAccessTokenValue, oauthAccessTokenSecret);
List <linkedinprofile> connections = template.getConnections();

Of course, the OAuth authorization portion is the tricky part. SpringSource has created a reference implementation called Greenhouse to demonstrate how to use the API. Greenhouse has some sample code that demonstrates requesting OAuth tokens and connecting to each provider, but an excellent Spring Social tutorial already written by Jettro Coenradie might be easier to follow.

Future milestones for Spring Social plan to include better documentation and more integrated management of OAuth services to store authorizations. At the moment, developers have to handle storing authorization keys somewhere and passing authorization keys to the Spring Social template. But the next Spring Social milestone will include code to make this process easier. SpringSource plans to base its ultimate OAuth solution on the code currently in Greenhouse.

Alternatives to Spring Social include using other, site-specific libraries. Twitter has the richest ecosystem of libraries like Twitter4J and others. Site-specific libraries for other sites are a little harder to come by, like the fork of Facebook's formerly official, now semi-abandoned Java API or RestFB.

Developers can also use OAuth helper libraries to do some heavy lifting and then just use the REST-like APIs of each service by directly manipulating URLs. Some popular OAuth libraries include Signpost, OAuth for Spring Security, Scribe, and others.

Rate this Article