private static void openBrowser(OAuthV2 oAuth) { String authorizationUrl = OAuthV2Client.generateAuthorizationURL(oAuth); // 调用外部浏览器 if (!java.awt.Desktop.isDesktopSupported()) { System.err.println("Desktop is not supported (fatal)"); System.exit(1); } java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop == null || !desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { System.err.println("Desktop doesn't support the browse action (fatal)"); System.exit(1); } try { desktop.browse(new URI(authorizationUrl)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } System.out.println( "Input the authorization information (eg: code=CODE&openid=OPENID&openkey=OPENKEY) :"); Scanner in = new Scanner(System.in); String responseData = in.nextLine(); in.close(); if (OAuthV2Client.parseAuthorization(responseData, oAuth)) { System.out.println("Parse Authorization Information Successfully"); } else { System.out.println("Fail to Parse Authorization Information"); return; } }