我使用它的API實現了reddit集成。下面是我的登錄代碼到reddit的:在Android的Reddit集成
private void LoginMethod(){
String jsonString = "";
DefaultHttpClient httpclient = new DefaultHttpClient();
final ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>(3);
fields.add(new BasicNameValuePair("user", "test"));//will ask for a user to enter the password later
fields.add(new BasicNameValuePair("passwd", "test11"));
fields.add(new BasicNameValuePair("api_type", "json"));
final HttpPost request = new HttpPost("https://ssl.reddit.com/api/login");
try {
request.setEntity(new UrlEncodedFormEntity(fields, HTTP.UTF_8));
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
jsonString = EntityUtils.toString(entity);
System.out.println("response from redit = " + jsonString);
JSONObject jObject = new JSONObject(jsonString);
modhash = jObject.getJSONObject("json").getJSONObject("data").getString("modhash");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
使用上面的方法,它唯一的作品有時,大多得到響應象下面這樣:
02-10 16:36:57.008: I/System.out(26970): <!doctype html>
02-10 16:36:57.008: I/System.out(26970): <html>
02-10 16:36:57.008: I/System.out(26970): <head>
02-10 16:36:57.008: I/System.out(26970): <title>Too Many Requests</title>
02-10 16:36:57.008: I/System.out(26970): <style>
02-10 16:36:57.008: I/System.out(26970): body {
02-10 16:36:57.008: I/System.out(26970): font: small verdana, arial, helvetica, sans-serif;
02-10 16:36:57.008: I/System.out(26970): width: 600px;
02-10 16:36:57.008: I/System.out(26970): margin: 0 auto;
02-10 16:36:57.008: I/System.out(26970): }
02-10 16:36:57.008: I/System.out(26970): h1 {
02-10 16:36:57.008: I/System.out(26970): height: 40px;
02-10 16:36:57.008: I/System.out(26970): background: transparent url(//www.redditstatic.com/reddit.com.header.png) no-repeat scroll top right;
02-10 16:36:57.008: I/System.out(26970): }
02-10 16:36:57.008: I/System.out(26970): </style>
02-10 16:36:57.008: I/System.out(26970): </head>
02-10 16:36:57.008: I/System.out(26970): <body>
02-10 16:36:57.008: I/System.out(26970): <h1>whoa there, pardner!</h1>
02-10 16:36:57.008: I/System.out(26970):
02-10 16:36:57.008: I/System.out(26970): <p>we're sorry, but you appear to be a bot and we've seen too many requests
02-10 16:36:57.008: I/System.out(26970): from you lately. we enforce a hard speed limit on requests that appear to come
02-10 16:36:57.008: I/System.out(26970): from bots to prevent abuse.</p>
02-10 16:36:57.008: I/System.out(26970): <p>if you are not a bot but are spoofing one via your browser's user agent
02-10 16:36:57.008: I/System.out(26970): string: please change your user agent string to avoid seeing this message
02-10 16:36:57.008: I/System.out(26970): again.</p>
02-10 16:36:57.008: I/System.out(26970): <p>please wait 3 second(s) and try again.</p>
02-10 16:36:57.008: I/System.out(26970): <p>as a reminder to developers, we recommend that clients make no
02-10 16:36:57.008: I/System.out(26970): more than <a href="http://github.com/reddit/reddit/wiki/API">one
02-10 16:36:57.008: I/System.out(26970): request every two seconds</a> to avoid seeing this message.</p>
02-10 16:36:57.008: I/System.out(26970): </body>
02-10 16:36:57.008: I/System.out(26970): </html>
我不知道如何處理這類問題。我已經做了R & D,但沒有太多的細節或例子可用於reddit集成。
那麼,有助於解決這個錯誤。
有費率限制。 http://www.reddit.com/r/webdev/comments/1z8tqk/reddit_api_rate_limit_question/請參閱https://github.com/reddit/reddit/wiki/API#rules – Kenneth 2015-02-10 11:18:52
我應該在我的代碼中更改哪些內容? – Riser 2015-02-10 12:00:03