Facilitating the spread of knowledge and innovation in professional software development



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


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.

We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • What does this replace?

    by Daniele Dellafiore,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    It's easy to understand that this is an integrated and spring-friendly alternatives to different social network specialized libraries but what about general purpose OAuth helper libraries like OAuth for spring and such?
    For exampl, I am starting to develop an app that uses the new Salesforce REST API that allow OAuth2 authentication. What's a suggested approach? Try to implement a SalesforceTemplate like the ones in Spring Social using the low level API or maybe use OAuth for Spring?

  • Craig Walls

    by Keith Donald,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Craig Walls, author of Spring in Action, is the lead of the Spring Social project, and has written a detailed blog post on the capabilities of the first Spring Social milestone, which includes a look to the future as well as step-by-step instructions on getting the Greenhouse reference application running locally for exploring its architecture. You can read Craig's article at the SpringSource Team Blog.

    A note about Greenhouse: while it does serve as a sample application, it is also hosted in production at, and was used to power the recent SpringOne2gx conference in Chicago, IL, allowing members to follow the event in real-time from their mobile phones. I point this out because you'll find production quality application code you can use not only as a learning tool, but code you can look to take advantage of in your own applications.


  • Re: What does this replace?

    by Keith Donald,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Spring Social does not replace anything--it's a higher-level project to help you build "social-ready" web apps that integrate various service providers such as Facebook and Twitter. It depends on a general purpose OAuth helper library to do this. As discussed in the comments on Craig's blog, Spring Social can work with two different OAuth libraries at present:
    #1. Spring Security OAuth, a subproject of Spring Security lead by Ryan Heaton that supports both OAuth 1 and 2 comprehensively.
    #2. Scribe, a OAuth 1.0 client library lead by Pablo Fernandez with a nice API.

    For your specific case, I would consider using the OAuth 2 client support in the Spring Security OAuth project. It's first milestone release under the umbrella is now available as well. Yes, I would recommend implementing a SalesforceOperations API similar to what you see in Spring Social for Twitter, Facebook, LinkedIn, and TripIt. This allows you to hide the OAuth and REST details, and gives callers a clean domain-oriented API to use.

    I would also recommend reviewing the "Service Provider" framework currently implemented in the Greenhouse project that provides an extensible model for registering new providers and establishing connections with them. As both Craig and Tim mentioned, this framework is being factored out from Greenhouse into Spring Social in a subsequent milestone. It makes the process of integrating a new ServiceProvider such as Salesforce into your application something like this:
    1. Create an API interface/implementation for the new ServiceProvider e.g. SalesforceOperations/SalesforceTemplate.
    2. Create a implementation of the ServiceProvider<S> interface e.g. SalesforceServiceProvider<SalesforceOperations>
    3. Register the ServiceProvider<S> implementation with the system.
    Once registered, users of your application can then establish connections to the provider. Once a connection is established, the application can then the Provider's Operations interface to invoke the API on behalf of the user.


  • Re: What does this replace?

    by Craig Walls,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    As Keith mentioned, Spring Social depends on an OAuth library to handle the task of signing requests with OAuth credentials. In milestone 1, Spring Social expects that you will have registered your application with the OAuth provider to receive your API key and secret and will have already gone through the "OAuth dance" to receive an access token for your user.

    However, a major focus of milestone 2 will be to bring the service provider framework in Greenhouse to Spring Social so that there is a more complete story of how OAuth details can be managed. To be a part of the Spring Social discussion, I invite you to visit the Spring Social forum at We want this project to be community-driven, so your input and involvement is greatly appreciated.

    As the OAuth 2 is still quite new, there aren't many options available for working with OAuth 2. But I encourage you to check out Ryan Heaton's Spring Security for OAuth (, as it has client support for OAuth 2 in its first milestone release. Also, be sure to visit the Spring Security for OAuth forum at for discussion on that topic.

  • Re: What does this replace?

    by Daniele Dellafiore,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Thanks for your answers Craig and Keith.

    I added spring social and oauth to my project where just yesterday I started to integrate with the brand new REST OAuth2 API for Salesforce. I'll move this discussion on the forum so maybe I will emerge with a SalesforceTemplate implementation instead of a custom one.

  • Sample Code on Spring Social Accessing Facebook

    by P@ul Rod,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I have made a sample code on how to use Spring Social in Accessing Facebook. Just wanna share it and hope it would help others too.. Accessing Facebook Using Spring Social .

  • Re: Sample Code on Spring Social Accessing Facebook

    by suresh m,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    The links is not working and i am getting a 404. Do you have an updated link?

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.