'PayPal Sandbox get access token api is refusing work from my java code
I have tried to access the REST api in order to get a PayPal access token, but something doesn't work there. I keep on getting code 403 (Forbidden) from the code.
The code is based on Jersey Jax-RS implmentation that's available on the Jakarta platform 9.1.0. Here's how it looks like:
try {
Invocation.Builder builder = client.target("https://api-m.sandbox.paypal.com/")
.path("v1/oauth2/token")
.request()
.accept("application/json")
.acceptLanguage("en_US")
.header("Authorization", this.httpHeaders.get("Authorization"))
.header("Content-Type", "application/x-www-form-urlencoded");
response = builder.post(Entity.entity("grant_type=client_credentials", MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class);
} catch (Exception e) {
e.printStackTrace();
}
the this.httpHeaders.get("Authorization") is where I stored the standard 'Basic ' + the base64 representation if the username:password.
In order to verify it's not an issue with my firewall i accessed the same api from windows 10 command line via cUrl and it works just find (I get a 200 ok reponse with a proper json block):
curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" \
-u "<CLIENT_ID>:<CLIENT_SECRET>" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials"
Obviously I am doing something wrong here. I would appreciate your help to tell me what is needed to be fixed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
