1

I'm trying to get access to the server via its API. There is a possibility of access without opening the browser, as in provided example

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

So I'm trying to use Google's API, specifically PasswordTokenRequest, basically copying the code from the javadoc I downloaded the 1.20.0 library through maven and every method and class was imported, but setRedirectUri() was not. IntelliJ IDEA keeps telling me that it can't resolve this method, though it was used in official documentation. So the example provided in javadoc is wrong? If so, what is the correct way to get access to API if it requires Bearer token and the POST body looks like this?

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"

1 Answer 1

1

As it turns out, the code provided in javadoc was wrong indeed. When I changed it this way, it worked:

      TokenResponse response =
      new PasswordTokenRequest(new NetHttpTransport(), new JacksonFactory(),
          new GenericUrl("https://server.example.com/token"), client_id, secret)
          .setClientAuthentication(
              new BasicAuthentication(username, password)).execute();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.