You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, you need to install ScribeJava. You either download two jars manually from the downloads page and http://mvnrepository.com/artifact/com.github.scribejava/scribejava-core and include apache commons codec, or just let maven take care of everything adding this to your pom.xml file:
<dependency>
<groupId>com.github.scribejava</groupId>
<artifactId>scribejava-apis</artifactId>
<version>6.4.1</version> // please use always the latest version
</dependency>
The example uses OOB OAuth, if you want to pass a callbackUrl so that Twitter redirects you there just add
a callback("http://your_callback_url") call before build()
After this either the user will get a verifier code (if this is an OOB request) or you’ll receive a redirect from Twitter with the verifier and the requestToken on it (if you provided a callbackUrl)
Step Four: Get the access Token
Now that you have (somehow) the verifier, you need to exchange your requestToken and verifier for an accessToken which is the one used to sign requests.
finalOAuth1AccessTokenaccessToken = service.getAccessToken(requestToken, "verifier you got from the user/callback");
Step Five: Sign request
You are all set to make your first API call, so let’s do it!
finalOAuthRequestrequest = newOAuthRequest(Verb.GET, "https://api.twitter.com/1.1/account/verify_credentials.json");
service.signRequest(accessToken, request); // the access token from step 4finalResponseresponse = service.execute(request);
System.out.println(response.getBody());
That’s it! You already know everything you need to start building a cool OAuth application.