2
我可以通过API登录到reddit,但我无法获得投票处理。这是为了让它工作而尝试减少案例。但是我回来的是“用户需要这样做”;有任何想法吗?Reddit投票API
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);
}
@Voo有一个API,但是 - 也许他们支持站点API,例如,使用移动应用程序。 SO API的下一个版本不会支持投票吗?您需要成为经过认证的用户才能投票,这是顶部的'modHash'值。弗雷德,你确定modhash是正确的吗? – Rup 2011-12-20 00:45:27
@RUP是的,我把它拉出来在这里发布,但它的头部,我相信是正确的。 – Fred 2011-12-20 00:51:17
投票机器人?接下来他们会希望[司机的liscenses](http://www.nytimes.com/2010/10/10/science/10google.html?pagewanted=all)。我们不能那样! – 2011-12-20 02:06:33