Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Simple Spring Social for Twitter Friends

DZone's Guide to

Simple Spring Social for Twitter Friends

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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

<dependencies>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>${spring.social.version}</version>
</dependency>
...
</dependencies>

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

<repositories>
<repository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
...
</repositories>

3. Create the TwitterTemplate, and ask for friends

TwitterTemplate twitterTemplate = new TwitterTemplate();
List<String> 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.

From http://gordondickens.com/wordpress/2011/01/03/simple-spring-social-for-twitter-friends/

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}