改造从api获取数据

时间:2018-11-27 13:52:32

标签: java get retrofit

我想向该网址发送请求 https://openlibrary.org/api/books?bibkeys=OL24226534M&jscmd=details&format=json

OL24226534M是一本书的ID,拥有一个保留10本书的ID的列表,并且ı希望对所有书籍一一发送请求,并获取该书的出版日期。

 @GET("/api/books")
Call<OLIDOL24226534M> callbookdetails(@Query("bibkeys") String bibkeys,
                                      @Query("jscmd") String jscmd,
                                      @Query("format") String format);






String details = "details";
String json = "json";

private String createyears(final ArrayList<String> years) {

    for (int i = 0 ; i<edlist.size(); i++){
        String edition = edlist.get(i); // edlist keeps id of books

        Call<OLIDOL24226534M> calldetail = mService.callbookdetails(edition,details,json);
        calldetail.enqueue(new Callback<OLIDOL24226534M>() {
            @Override
            public void onResponse(Call<OLIDOL24226534M> call, retrofit2.Response<OLIDOL24226534M> response) {
                bookyear = response.body().getDetails().getPublishDate();
                years.add(bookyear);
            }
            @Override
            public void onFailure(Call<OLIDOL24226534M> call, Throwable t) {
                Log.e("TAG","Fail",t);
            }
        });
    }

    return bookyear;
}

但是代码不会进入onResponse或OnFailure。

0 个答案:

没有答案