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 {
// Replace these with your own api key and secret
String apiKey = "YOUR_API_KEY"; //Give your own API Key
String apiSecret = "YOUR_API_SECRET"; //Give your own 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"); //Copy the new token you get here
accessToken = checkToken(vimeoAPIURL, accessToken, service);
if (accessToken == null) {
return;
}
}
/**
* Checks the token to make sure it's still valid. If not, it pops up a dialog asking the user to
* authenticate.
*/
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;
}
/**
* Gets authorization URL, pops up a dialog asking the user to authenticate with the url and the user
* returns the authorization code
*
* @param service
* @return
*/
private static Token getNewToken(OAuthService service) {
// Obtain the Authorization URL
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);
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
try {
Token token = service.getAccessToken(requestToken, verifier);
System.out.println(token); //Use this output to copy the token into your code so you don't have to do this over and over.
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;
}
/**
* Signs the request and sends it. Returns the response.
*
* @param request
* @return response
*/
public static Response signAndSendToVimeo(OAuthRequest request) throws org.scribe.exceptions.OAuthException {
service.signRequest(accessToken, request);
Response response = request.send();
return response;
}