Skip to content
rajithd edited this page Dec 3, 2011 · 1 revision

Step One: Install Scribe

First of all, you need to install scribe. You either download the jar manually from the downloads page and include apache commons codec, or just let maven take care of everything adding this to your pom.xml file:

<dependency> <groupId>org.scribe</groupId> <artifactId>scribe</artifactId> <version>1.1.2</version> </dependency>

Step two: Create the OAuthService object

OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("your_api_key") .apiSecret("your_api_secret") .build();

Step three: Get the request token

Token requestToken = service.getRequestToken()

Step four: Making the user validate your request token

String authUrl = service.getAuthorizationUrl(requestToken)

Step five: Get the access Token

Verifier v = new Verifier("verifier you got from the user"); Token accessToken = service.getAccessToken(requestToken, verifier);

Step six: Sign request

OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.twitter.com/1/account/verify_credentials.xml"); service.signRequest(accessToken, request); // the access token from step 4 Response response = request.send(); System.out.println(response.getBody());