Я могу войти в Reddit через API с Java, но не могу получить голос для обработки.Это была попытка сократить дело, чтобы заставить его работать.Но все, что я получаю, это «Пользователь обязан это сделать»;есть идеи?
String apiParams = "api_type=json&id=c38ghjg&dir=1&uh=" + modHash;
URL voteURL = new URL("http://www.reddit.com/api/vote");
HttpURLConnection connection = (HttpURLConnection) voteURL.openConnection ();
connection.setDoOutput (true);
connection.setRequestMethod ("POST");
connection.setUseCaches (false);
connection.setRequestProperty ("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8" );
connection.setRequestProperty("cookie", "reddit_session="+cookie);
connection.setRequestProperty ("Content-Length",
String.valueOf( apiParams.length() ));
DataOutputStream wr = new DataOutputStream( connection.getOutputStream() );
wr.writeBytes( apiParams );
wr.flush();
wr.close();
InputStream cis = connection.getInputStream();
HashMap<String, String> parameters = new HashMap<String,String> ();
if(cis != null){
ObjectMapper mapper = new ObjectMapper ();
TypeReference<Map<String, Object>>
mapReference = new TypeReference<Map<String, Object>> () { };
Map<String, Object> resultJSON = mapper.readValue (cis, mapReference);
Map<String, Object> json = (Map<String, Object>) resultJSON.get ("json");
Map<String, Object> data = (Map<String,Object>) json.get ("data");
System.out.println(json);
}