Auth Exception in Pinterest API

南笙酒味 提交于 2019-12-09 14:00:29

问题


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){}
  }

来源:https://stackoverflow.com/questions/32836540/auth-exception-in-pinterest-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!