Back to Blog
January 17, 2011·Tracey Welson-Rossman

Simple Spring Social for Twitter Friends

The Spring Social project provides us developers with an easy way to interact with Twitter, Facebook, LinkedIn & TripIt via the familiar Template objects we have used. Spring has provided Templates for convenient interaction with JDBC, REST, Hibernate, JNDI, and more.

One of the simplest social media calls is to lookup someone's Twitter friends with the TwitterTemplate.

1. Add the Spring Social project dependency to the pom.xml file

javascript
  org.springframework.social spring-social-core ${spring.social.version}  ... 

2. Add the Spring Milestone Repository repository to the pom.xml file

javascript
  spring-maven-milestone Spring Maven Milestone Repository http://maven.springframework.org/milestone  ... 

3. Create the TwitterTemplate, and ask for friends

javascript
TwitterTemplate twitterTemplate = new TwitterTemplate();
List friends = twitterTemplate.getFriends("chariotsolution"); for (String friend : friends) { System.out.println("Friend: " + friend); } 

4. Use the code above anywhere in your application

In the next blog, I will cover how to use Open Authentication (OAuth) to perform more Twitter operations.

Comments

Ready to transform your business?

We solve complex business problems with technology. Let's discuss how we can help you build, modernize, and grow.

Start A Conversation