Java 使用loopj向AsyncHttpClient添加反Bounce
我有一个从GoogleBooksAPI读取数据的应用程序 我在图书id上运行for循环,对于每个id,我可以使用API来获得结果 据我所知,我将请求发送到fast,但我收到一个错误消息:请求太多,我应该减慢请求的速度 我使用以下代码获取API数据:Java 使用loopj向AsyncHttpClient添加反Bounce,java,android,android-asynctask,httpclient,debounce,Java,Android,Android Asynctask,Httpclient,Debounce,我有一个从GoogleBooksAPI读取数据的应用程序 我在图书id上运行for循环,对于每个id,我可以使用API来获得结果 据我所知,我将请求发送到fast,但我收到一个错误消息:请求太多,我应该减慢请求的速度 我使用以下代码获取API数据: public class MyBookClient { private static final String API_BASE_URL = "https://www.googleapis.com/books/v1/volumes
public class MyBookClient {
private static final String API_BASE_URL = "https://www.googleapis.com/books/v1/volumes/";
private AsyncHttpClient client;
public static MyBookClient instance = new MyBookClient();
public MyBookClient() {
this.client = new AsyncHttpClient();
}
public static MyBookClient getInstance() {
return instance;
}
public void getBooks(final String query, JsonHttpResponseHandler handler) {
try {
client.get( API_BASE_URL + URLEncoder.encode( query, "utf-8" ), handler );
} catch (UnsupportedEncodingException ignored) {
}
}
}
然后在recyclerView适配器内:
MyBookClient.getInstance().getBooks( BookID, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
if (response != null) {
final MyBook books = MyBook.fromJson( response );
tv_Title.setText( books.getTitle() );
tv_Author.setText( books.getAuthor() );
Picasso.with( itemView.getContext() ).load( Uri.parse( books.getCoverUrl() ) ).error( R.drawable.ic_nocover ).resize( 110, 160 ).into( Iv_BookCover );
}
}
} );
其中BookID在每次循环迭代中都会更改
我怎样才能在代码中添加谴责或其他内容,使其不会返回此消息
多谢各位