I am getting { "status": "failure", "code": 3, "host": "coreapp-devplatform-devapi-173", "generated_at": "Tue, 29 Sep 2015 05:42:42 +0000", "message": "Authorization failed.", "data": null } exception while invoking https://api.pinterest.com/v1/oauth/token?code=&client_id=&grant_type=authorization_code. Can anyone help me to resolve this?
Code:
if (request.getParameter("code") != null) { code = request.getParameter("code"); } String authorizeUrl = "https://api.pinterest.com/v1/oauth/token"; String postStr = "code=" + code + "&client_id=" + clientId + "&grant_type=authorization_code"; String responseStr = postTokenRequest(authorizeUrl, postStr); //Method public String postTokenRequest(String serverURL, String content) { String inputLine = ""; HttpsURLConnection connection = null; URL url = new URL(serverURL); String method = "POST"; InputStream connectionIn = null; BufferedReader buffer = null; try { connection = (HttpsURLConnection) url.openConnection(); connection.setRequestProperty("Content-Length", String.valueOf(content.getBytes().length)); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setDoOutput(true); connection.getOutputStream().write(content.getBytes()); int returnCode = connection.getResponseCode(); if (returnCode == 200) { connectionIn = connection.getInputStream(); } else { connectionIn = connection.getErrorStream(); } buffer = new BufferedReader(new InputStreamReader(connectionIn)); StringBuilder sb = new StringBuilder(); while ((inputLine = buffer.readLine()) != null) { sb.append(inputLine); } buffer.close(); return sb.toString(); }catch(Exception e){} }