I have a process that gets an Authentication token with no issue, Then the process runs trying to get an access token. When this runs I always get a 400 Error. The process uses the Auth Token received just seconds ago.... always get a 400 Error. Request to get Authorization token goes to (with id and domain obscured of course): https://idfed.constantcontact.com/as/authorization.oauth2?pfidpadapterid=ctctOAuth2IdpAdapter&client_id=x#xxxx#x-x#x#-####-#x##-#xx#xxx#####&response_type=code&scope=contact_data&redirect_uri=https://mydomain.com/862578EF0082BEF8/oauthinitcc.xsp This returns an Authorization code that is generally 40 characters long. I then pass it to a url like the following (tweaked again of course): https://idfed.constantcontact.com/as/token.oauth2?code=ihvDmqXaltqX25EtNjXWU28npLAS62g1BVpULgDJ&grant_type=authorization&redirect_uri=https://mydomain.com/862578EF0082BEF8/oauthlistcc.xsp The immediately above url is generated in Java code, and a "POST" using HttpsURLConnection (just like the API Doc examples show) is used. However, the first line to investigate the result of the HttpsURLConnection throws a 400 Error. The basic code is below (obscured). StringBuilder authResult = new StringBuilder(); // Make authorization header with API Key:API Secret and encode System.out.println("thisAPIKey = " + thisAPIKey); System.out.println("thisAPISecret = " + thisAPISecret); String credentials = thisAPIKey + ":" + thisAPISecret; //Content-Type: application/x-www-form-urlencoded String auth = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes()); //String auth = DatatypeConverter.printBase64Binary(credentials.getBytes()); System.out.println("auth is set without error"); System.out.println("auth = " + auth.toString()); // Create request URL StringBuilder requestUrl = new StringBuilder() .append("https://idfed.constantcontact.com/as/token.oauth2") .append("?code=") .append(codeParam) // this is the AuthorizationCode that is retrieved initially and passed to this process .append("&grant_type=authorization_code") .append("&redirect_uri=") .append(redirectUri); URL authorizeUrl = new URL(requestUrl.toString()); System.out.println("URL is set"); HttpsURLConnection con = null; con = (HttpsURLConnection) authorizeUrl.openConnection(); SSLContext sc = SSLContext.getInstance("TLSv1.2"); sc.init(null, null, new java.security.SecureRandom()); con.setSSLSocketFactory(sc.getSocketFactory()); System.out.println("connection is made"); // Set Method con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Add Auth Header con.setRequestProperty("Authorization", auth); con.setDoInput(true); InputStream content = null; BufferedReader inVal = null; con.setConnectTimeout(40000); // Read response from server inVal = new BufferedReader(new InputStreamReader(con.getInputStream())); Everything is running fine up to the last line above, which is the first attempt to use the return information from the HttpsURLConnection. The error I get from Java is an IOException error: java.io.IOException: Server returned HTTP response code: 400 for URL: https://idfed.constantcontact.com/as/token.oauth2?code=ihvDmqXaltqX25EtNjXWU28npLAS62g1BVpULgDJ&grant_type=authorization&redirect_uri=https://mydomain.com/862578EF0082BEF8/oauthlistcc.xsp Any help would be appreciated. I have spent a fair amount of time trying to solve on my own with no success. Thanks Mike KInder
... View more