RestFul Web サービスを呼び出す Java クライアント コードを作成するのは初めてです。OAuth2.0 セキュリティを使用するこれらの Web サービス。クライアント ID と秘密鍵を持っていますが、Java プログラムから呼び出すことができません。これからアクセス トークンを取得し、このトークンをさらに Web サービス API 呼び出しに使用するにはどうすればよいですか。これが私が試した方法です:
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();
}
}
}
Bad Request エラー メッセージが表示されます。
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