我试图向linkedin提供的oauth url发出get请求,对于响应,我应该获得授权码。然而,使用下面的代码,当我进入linkedin oauth页面,在那里我必须键入我的电子邮件和密码,在我键入我的凭据后,我得到了授权代码,但我无法通过我的代码访问它。但是,重定向到我的网站后,我可以在url中看到授权代码,如code=asdasdasa。。。。如何通过url访问此代码?我应该使用httpurlconnection还是什么?我还想通过一个html按钮转到url。
public static void getAuthorizationCode() throws IOException, InterruptedException {
String authorizationUri = "https://www.linkedin.com/oauth/v2/authorization?response_type=code" +
"&client_id=" + CLIENT_ID +
"&redirect_uri=" + REDIRECT_URI +
"&scope=r_liteprofile%20r_emailaddress";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create(authorizationUri))
.build();
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(httpResponse.previousResponse() + "\n\n");
System.out.println(httpResponse.request() + "\n\n");
System.out.println(httpResponse.statusCode()+ "\n\n");
JSONObject jo = new JSONObject(httpResponse);
System.out.println(jo.getJSONArray("access_token"));
}
暂无答案!
目前还没有任何答案,快来回答吧!