I am new to write a Java client code to call RestFul web services. These web services using OAuth2.0 security. I have client-id and secret keys with me, but unable to call through Java program. How should I get access token out of this and use this token further for Web service API calls. Here is how I tried:
private static void authorizationProcess() throws ClientProtocolException, IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpContext context = new BasicHttpContext();
HttpGet httpGet = new HttpGet("https://www.ustream.tv/oauth2/authorize?response_type=token&client_id=671c71f800c17f1d57f10eebeba2f42d230143cddji8&redirect_uri=www.ustream.tv");
try {
HttpResponse httpResponse = httpClient.execute(httpGet, context);
System.out.println("Response status: " + httpResponse.getStatusLine());
HttpRequest req = (HttpRequest) context.getAttribute(
ExecutionContext.HTTP_REQUEST);
System.out.println("Last request URI: " + req.getRequestLine());
RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(
DefaultRedirectStrategy.REDIRECT_LOCATIONS);
if (redirectLocations != null) {
System.out.println("All intermediate redirects: " + redirectLocations.getAll());
}
EntityUtils.consume(httpResponse.getEntity());
} finally {
httpGet.releaseConnection();
}
}
}
Its giving Bad Request error message:
Response status: HTTP/1.1 400 Bad Request
Last request URI: GET /oauth2/authorize?response_type=token&client_id=671c71f800c17f1d57f10eebeba2f42d230143cddji8& redirect_uri=www.ustream.tv HTTP/1.1