Don't know whether you're still having a problem with this, but you might try using scribe. I've been developing an application for vimeo and relying heavily on Scribe to sign and send my requests. Here's an example for authentication and signing and sending a request:
private static OAuthService service;
private static Token accessToken;
private static String newline = System.getProperty("line.separator");
public static void main(String[] args) throws Exception {
String apiKey = "YOUR_API_KEY";
String apiSecret = "YOUR_API_SECRET";
String vimeoAPIURL = "http://vimeo.com/api/rest/v2";
service = new ServiceBuilder().provider(VimeoApi.class).apiKey(apiKey).apiSecret(apiSecret).build();
OAuthRequest request;
Response response;
accessToken = new Token("AN_INVALID_TOKEN_WILL", "REQUIRE_GETTING_A_NEW_ONE");
accessToken = checkToken(vimeoAPIURL, accessToken, service);
if (accessToken == null) {
return;
}
}
private static Token checkToken(String vimeoAPIURL, Token vimeoToken, OAuthService vimeoService) {
if (vimeoToken == null) {
vimeoToken = getNewToken(vimeoService);
} else {
OAuthRequest request = new OAuthRequest(Verb.GET, vimeoAPIURL);
request.addQuerystringParameter("method", "vimeo.oauth.checkAccessToken");
Response response = signAndSendToVimeo(request, "checkAccessToken", true);
if (response.isSuccessful()
&& (response.getCode() != 200 || response.getBody().contains("<err code=\"302\"")
|| response.getBody().contains("<err code=\"401\""))) {
vimeoToken = getNewToken(vimeoService);
}
}
return vimeoToken;
}
private static Token getNewToken(OAuthService service) {
Token requestToken = service.getRequestToken();
String authorizationUrl = service.getAuthorizationUrl(requestToken);
do {
String code = JOptionPane.showInputDialog("The token for the account (whatever)" + newline
+ "is either not set or is no longer valid." + newline
+ "Please go to the URL below and authorize this application." + newline
+ "Paste the code you're given on top of the URL here and click \'OK\'" + newline
+ "(click the 'x' or input the letter 'q' to cancel." + newline
+ "If you input an invalid code, I'll keep popping up).", authorizationUrl + "&permission=delete");
if (code == null) {
return null;
}
Verifier verifier = new Verifier(code);
System.out.println("Trading the Request Token for an Access Token...");
try {
Token token = service.getAccessToken(requestToken, verifier);
System.out.println(token);
return token;
} catch (OAuthException ex) {
int choice = JOptionPane.showConfirmDialog(null, "There was an OAuthException" + newline
+ ex + newline
+ "Would you like to try again?", "OAuthException", JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.NO_OPTION) {
break;
}
}
} while (true);
return null;
}
public static Response signAndSendToVimeo(OAuthRequest request) throws org.scribe.exceptions.OAuthException {
service.signRequest(accessToken, request);
Response response = request.send();
return response;
}