Tôi đang cố triển khai trợ cấp ngầm OAuth 2.0 từ ứng dụng máy khách java dành cho máy tính để bàn bằng cách sử dụng API RESTDrive REST. Tôi sử dụng đoạn mã sau:Truy xuất mã thông báo truy cập của OAuth 2.0 (trợ cấp ngầm định) từ Máy khách Java Desktop bằng cách sử dụng API RESTDrive REST.
Desktop.getDesktop().browse(new URL(st.toString()).toURI());
JOptionPane.showMessageDialog(null, "Press ok to continue once you have authenticated.");
mã của tôi mở trình duyệt web và yêu cầu người dùng đăng nhập và sau đó SkyDrive gửi access token để url trình duyệt theo hình thức sau:
https://login.live.com/oauth20_desktop.srf?lc=1033#access_token=EwAwAq1DBAAUlbRW.....
Những gì tôi muốn làm là đọc mã thông báo truy cập này từ chương trình java của tôi. Tôi đã cố đọc httpconnection từ bảng điều khiển:
HttpURLConnection con = (HttpURLConnection) url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
while(reader.readLine()!=null){
System.out.println(reader.readLine());
nhưng có vẻ như java httpurlconnection không xử lý phản hồi javascript. Trả lời:
<html dir="..... Windows Live ID requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked......<body onload="evt_LoginHostMobile_onload(event);">
Vì vậy, có cách nào để truy xuất mã thông báo truy cập trực tiếp từ java không?