0
votes

This is my code. I am not using Maven or curl.

String encoding = Base64.encodeBase64String((clientId + ":" + clientSecret).getBytes());
encoding = encoding.replaceAll("\n", "");

URL url1 = new URL("https://api.sandbox.paypal.com/v1/oauth2/token");
HttpURLConnection conn = (HttpURLConnection) url1.openConnection();

conn.setRequestMethod("POST");
conn.setRequestProperty("grant_type", "client_credentials");
conn.setRequestProperty("Authorization", "Basic " + encoding);

System.out.println(conn.getResponseCode());

if (conn.getResponseCode() == 500) {
InputStream error = conn.getErrorStream();
BufferedReader er = new BufferedReader(new InputStreamReader(error));
String erLine;
while ((erLine = er.readLine()) != null) {
System.out.println(erLine);
}
}

InputStream content = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
conn.disconnect();

OUTPUT:

500 {"name":"INTERNAL_SERVICE_ERROR","information_link":"https://api.sandbox.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"023ff49775e72"}

PROBLEM:

Well, when I do this call using curl, it gives me an appropriate response. Are the services not equipped to do communication is this way ?

1
So, in what language is your chunk of code? BTW, it's nice that the information_link it's dead...Braiam
I am coding in Java. They have a sdk which allows me do all of this. But I was trying to avoid Maven installation in my system.UnitedSince88
You can still use the SDK without using maven. You can download the JAR plus sample app as a zip here paypal.github.io/#payments-tab-javaPrasanna_PayPal
Yea @Prasanna_Paypal, I got it working with the SDK. Finally. Thanks. At first, I was not able to build my application probably because of some conflicting jars.UnitedSince88

1 Answers

0
votes

Can you print your Authorization header and inspect whether it's correctly populated? We are currently returning a HTTP500 if your Authorization header is empty (which we'll change to return a more appropriate error obviously).