我知道SOF有很多类似的问题,但我没有在他们身上找到对我有用的东西。按照谷歌自定义搜索文档,&start
参数:如何显示谷歌自定义搜索结果的下一页?
The start parameter uses a zero-based index, meaning the first result is 0, the second result is 1 and so forth.
The start parameter works in conjunction with the num parameter to determine which search results to return.
我试着从零发送,但应用程序崩溃。在这种尝试我试图发送:
1页:&num=10&start=1
2页:&num=10&start=11
,但它仍然要求1页。 &start
参数总是被忽略
我写一个Android应用程序,它不会像搜索,上向下滚动应该dislpays下一页(未来10张),在android系统,它总是返回1页有10幅图像,我测试要求在浏览器中,加上&num
参数,它的工作原理。在Android上,似乎在第一次加载页面后,忽略参数&start
和&num
。
我与改造结合使用robospice,我想不出get request串怎么看,也许我做错了什么
这里是我的接口:
public static final String BASE_URL = "https://www.googleapis.com/customsearch";
public static final String API_KEY = "AIzaSyCCuxxVLzm2sZP-adhRNYKeSck1mMMgsAM";
public static final String CUSTOM_SEARCH_ID = "001734592082236324715:sob9rqk49yg";
public static final String SEARCH_TYPE_IMAGE = "image";
static final String FILTER = "&fields=queries(nextPage(startIndex,count),request(startIndex,count)),searchInformation(totalResults),items(title,link,displayLink,mime," +
"image)";
static final String QUERY = "/v1?key="+API_KEY+
"&cx="+CUSTOM_SEARCH_ID+
"&searchType="+SEARCH_TYPE_IMAGE+FILTER+"&num=10";
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
@Query("start") long startIndex);
SpiceRequest
public class SampleRetrofitSpiceRequest extends RetrofitSpiceRequest<GoogleSearchResponse,GoogleSearchInterface> {
String query;
long startIndex;
public SampleRetrofitSpiceRequest(String query, long startIndex) {
super(GoogleSearchResponse.class, GoogleSearchInterface.class);
this.query = query;
this.startIndex = startIndex;
}
@Override
public GoogleSearchResponse loadDataFromNetwork() throws Exception {
return getService().search(query,startIndex);
}}
SpiceService
public class SampleRetrofitSpiceService extends RetrofitGsonSpiceService {
@Override
public void onCreate() {
super.onCreate();
addRetrofitInterface(GoogleSearchInterface.class);
}
@Override
protected String getServerUrl() {
return GoogleSearchInterface.BASE_URL;
}}
现在我怎么生要求拿到第一结果页面,在页面的参数我送1,在获得第二页我送11:
public void sendRequest(String query,int page){
searchQuery = query;
request = new SampleRetrofitSpiceRequest(query, page);
spiceManager.execute(request, query, DurationInMillis.ONE_WEEK, new RequestImageListener());
request=null;
}
这里是响应监听器,下一页是一个号的下一个页面:
private class RequestImageListener implements RequestListener<GoogleSearchResponse> {
@Override
public void onRequestFailure(SpiceException spiceException) {
Toast.makeText(context, "failure", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(GoogleSearchResponse s) {
Toast.makeText(context,"success",Toast.LENGTH_SHORT).show();
nextPage = s.queries.getNextPage().startIndex;
Log.d("myTag","nextPage "+currentPage);
updateSearchResults(s.items);
}
}
UPDATE日志显示自定义SpiceRequest
不会提出新的请求,即使我创建新的实例。
你发现了如何做到这一点?答案有帮助吗? – Nobody