对不起我搞错了!
获取方法使用浏览器并返回代码
Post方法使用HttpRequest,我们可以从HtppResponse获取参数
因此,如果您想获取代码,只需使用浏览器并重定向到网址即可获取代码
这是我如何获得access_token
如果你愿意,你可以使用google-oauth-java-client来授权twitter facebook
我通过javadoc解决了这个问题,它向我展示了一些例子
This是JavaDoc的根
This是我用来解决的包裹
这是我写的例子
// https://server.example.com/token server url example
try {
TokenResponse response =
new AuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),
new GenericUrl("here is the server url "), "here write your code")
.setRedirectUri("here write the redirectUrl")
.set("client_id","here write your client_id")
.set("client_secret","here write your client_secret")
.set("Other else need","Other else need")
.execute();
System.out.println("Access token: " + response.getAccessToken());
} catch (TokenResponseException e) {
if (e.getDetails() != null) {
System.err.println("Error: " + e.getDetails().getError());
if (e.getDetails().getErrorDescription() != null) {
System.err.println(e.getDetails().getErrorDescription());
}
if (e.getDetails().getErrorUri() != null) {
System.err.println(e.getDetails().getErrorUri());
}
} else {
System.err.println(e.getMessage());
}
}