我得到{“状态”:“失败”,“代码”:3,“主持人”:“coreapp-devplatform-devapi-173”,“generated_at”:“星期二,2015年9月29日05:42:42 +0000“,”message“:”授权失败。“,”data“:null}异常,同时调用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){}
}