如何使用GoogleOAuthJava客户端?

如何使用GoogleOAuthJava客户端?,java,google-oauth,Java,Google Oauth,我想使用google oauth java client从中获取授权代码 这是从新浪获取代码的GET方法 https://api.weibo.com/oauth2/authorize?client_id=70090552&response_type=code&redirect_uri=http://127.0.0.1/weibo 请在没有网页的情况下解决此问题,仅限客户端 有谁能给我一些建议吗?你可以找到解决办法 并将帮助您。首先了解该机制,并根据您的场景实施它。很抱歉我犯了一

我想使用google oauth java client从中获取授权代码

这是从新浪获取代码的GET方法

https://api.weibo.com/oauth2/authorize?client_id=70090552&response_type=code&redirect_uri=http://127.0.0.1/weibo
请在没有网页的情况下解决此问题,仅限客户端

有谁能给我一些建议吗?

你可以找到解决办法


并将帮助您。首先了解该机制,并根据您的场景实施它。

很抱歉我犯了一个错误! 使用浏览器获取方法并返回代码 Post方法使用HttpRequest,我们可以从HttpResponse获取参数

所以,如果您想获取代码,只需使用浏览器并重定向到url即可获取代码

以下是我获取访问令牌的方式

如果您愿意,您可以使用google oauth java客户端授权twitter facebook

我通过javadoc解决了这个问题,它向我展示了一些示例 是JavaDoc的根 是我用来解决问题的软件包吗 这是我写的例子

//   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());
  }
}

似乎GoogleOAuth客户端只适用于GoogleServices,它在帖子正文中都有clientid和clientsecret。然而,其他oauth服务器通常在Base64编码后的POST头授权字段中有这些。看起来更像是注释而不是答案。