【问题标题】:Google OAuth api谷歌 OAuth api
【发布时间】:2018-02-27 23:28:21
【问题描述】:

我正在尝试通过其 API 访问服务器。有可能在不打开浏览器的情况下访问,如提供的示例中所示

curl "token url" -d "grant_type=password&client_id=&client_secret=&username=&password="

所以我正在尝试使用 Google 的 API,特别是 PasswordTokenRequest,基本上是从 javadoc 复制代码 我通过 maven 下载了 1.20.0 库并导入了每个方法和类,但 setRedirectUri() 没有。 IntelliJ IDEA 一直告诉我它无法解决这个方法,尽管它在官方文档中使用过。那么javadoc中提供的示例是错误的吗?如果是这样,如果它需要 Bearer 令牌并且 POST 正文看起来像这样,那么访问 API 的正确方法是什么?

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer 859ea2450228a5d655e3a8c2f9a5aedc30b591df" --header "Accept-Language: en" -d "{
  \"jsonrpc\": \"2.0\",
  \"method\": \"getByID\",
  \"params\": {
    \"Id\": 1
  },
  \"id\": 1
}" "rpc url"

【问题讨论】:

    标签: java json oauth-2.0 google-api-java-client google-oauth


    【解决方案1】:

    事实证明,javadoc 中提供的代码确实错误。当我以这种方式更改它时,它起作用了:

          TokenResponse response =
          new PasswordTokenRequest(new NetHttpTransport(), new JacksonFactory(),
              new GenericUrl("https://server.example.com/token"), client_id, secret)
              .setClientAuthentication(
                  new BasicAuthentication(username, password)).execute();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 2021-08-11
      • 2021-10-02
      • 1970-01-01
      相关资源
      最近更新 更多