Java Reference
In-Depth Information
public static String escape(String value) {
return ESCAPER.escape(value);
}
public void initialize(HttpRequest request) throws IOException {
request.setInterceptor(this);
}
public void intercept(HttpRequest request) throws IOException {
computeNonce();
computeTimestamp();
try {
computeSignature(request.getRequestMethod(), request.getUrl(),
request.getContent());
} catch (GeneralSecurityException e) {
IOException io = new IOException();
io.initCause(e);
throw io;
}
request.getHeaders().setAuthorization(getAuthorizationHeader());
}
}
Don't be too concerned about how this code works; it is basically the same as OAuthParameters ,
with the addition that it now also includes POST data to compute the signature.
Next, go back to the TwitterTest class and modify it as follows:
package com.twitter.api;
import java.util.HashMap;
public class TwitterTest {
private static final String CONSUMER_KEY = "FILL IN YOUR API KEY";
private static final String CONSUMER_SECRET = "FILL IN YOUR SECRET KEY";
private static final String REQUEST_TOKEN_URL =
" https://api.twitter.com/oauth/request_token" ;
private static final String AUTHORIZE_URL =
" https://api.twitter.com/oauth/authenticate" ;
private static final String ACCESS_TOKEN_URL =
" https://api.twitter.com/oauth/access_token" ;
public static void main(String[] args) throws Exception {
OAuthPostSignatureParametersProvider parametersProvider =
new OAuthPostSignatureParametersProvider("twitter",
CONSUMER_KEY, CONSUMER_SECRET,
REQUEST_TOKEN_URL, AUTHORIZE_URL, ACCESS_TOKEN_URL,
true);
TwitterRESTClient client = new TwitterRESTClient(parametersProvider);
String jsonResponse;
Search WWH ::




Custom Search