I know that SOF has many similar questions, but I did not find anything useful in them for me. According to the Google Custom Search documentation, the parameter is &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.
I tried sending from scratch, but the application crashed. In this attempt, I try to send:
for 1 page: &num=10&start=1
for 2 pages: &num=10&start=11
but he still requests 1 page. &startalways ignored.
I am writing an Android application that searches for images, when scrolling down it should display the next page (next 10 images), in android it always returns 1 page with 10 images, I tested the request in a browser, with a parameter &num, and it works. Androids seems that after loading the first page of options &startand &numignored.
I use robospice in conjunction with a modification, and I canβt figure out how to get a request to see, maybe I did something wrong
Here is my interface:
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;
}
-, nextPage - :
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);
}
}
, SpiceRequest , .