如何获取发送到 robospice 改造的请求字符串 URL?
How can I get request string URL that sent to robospice retrofit?
我搜索过但没有找到有用的信息。尝试处理 REST API 客户端,我将 robospice 与 retofit 结合使用,我想查看发送到服务的请求字符串。是否可以从 Robospice 或 Retrofit 中提取整个字符串 URL?
这是我的界面:
public interface GoogleSearchInterface {
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;
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
@Query("start") long startIndex);
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
@Query("start") long startIndex,
@Query("searchType") String searchType,
@Query("limit") String limit,
@Query("offset") String offset);
SpiceRequest
String query;
long startIndex;
String limit;
String offset;
public SampleRetrofitSpiceRequest(String query,long startIndex,String limit,String offset) {
super(GoogleSearchResponse.class,GoogleSearchInterface.class);
this.query = query;
this.startIndex = startIndex;
this.limit=limit;
this.offset=offset;
}
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);
}
香料服务
public class SampleRetrofitSpiceService extends RetrofitGsonSpiceService {
@Override
public void onCreate() {
super.onCreate();
addRetrofitInterface(GoogleSearchInterface.class);
}
@Override
protected String getServerUrl() {
return GoogleSearchInterface.BASE_URL;
}
发送请求的方法
public void sendRequest(String query,int page){
searchQuery = query;
request = new SampleRetrofitSpiceRequest(query, page);
spiceManager.execute(request, query, DurationInMillis.ONE_WEEK, new RequestImageListener());
/* try {
spiceManager.getFromCache(GoogleSearchResponse.class, "country",DurationInMillis.ONE_WEEK,new RequestImageListener());
}catch(Exception e){
e.printStackTrace();
}*/
request=null;
}
P.S。我正在编写一个将进行图像搜索的应用程序,前 10 个结果成功加载但下一页重复上一页。我花了很多时间,忽略了在 spiceRequst 中发送的 google api 的 &start 参数。谢谢。
解决方案是在 自定义 SpiceService.class
中覆盖此方法
@Override
protected RestAdapter.Builder createRestAdapterBuilder() {
RestAdapter.Builder builder = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setConverter(getConverter())
.setEndpoint(getServerUrl());
return builder;
}
我搜索过但没有找到有用的信息。尝试处理 REST API 客户端,我将 robospice 与 retofit 结合使用,我想查看发送到服务的请求字符串。是否可以从 Robospice 或 Retrofit 中提取整个字符串 URL?
这是我的界面:
public interface GoogleSearchInterface {
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;
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
@Query("start") long startIndex);
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
@Query("start") long startIndex,
@Query("searchType") String searchType,
@Query("limit") String limit,
@Query("offset") String offset);
SpiceRequest
String query;
long startIndex;
String limit;
String offset;
public SampleRetrofitSpiceRequest(String query,long startIndex,String limit,String offset) {
super(GoogleSearchResponse.class,GoogleSearchInterface.class);
this.query = query;
this.startIndex = startIndex;
this.limit=limit;
this.offset=offset;
}
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);
}
香料服务
public class SampleRetrofitSpiceService extends RetrofitGsonSpiceService {
@Override
public void onCreate() {
super.onCreate();
addRetrofitInterface(GoogleSearchInterface.class);
}
@Override
protected String getServerUrl() {
return GoogleSearchInterface.BASE_URL;
}
发送请求的方法
public void sendRequest(String query,int page){
searchQuery = query;
request = new SampleRetrofitSpiceRequest(query, page);
spiceManager.execute(request, query, DurationInMillis.ONE_WEEK, new RequestImageListener());
/* try {
spiceManager.getFromCache(GoogleSearchResponse.class, "country",DurationInMillis.ONE_WEEK,new RequestImageListener());
}catch(Exception e){
e.printStackTrace();
}*/
request=null;
}
P.S。我正在编写一个将进行图像搜索的应用程序,前 10 个结果成功加载但下一页重复上一页。我花了很多时间,忽略了在 spiceRequst 中发送的 google api 的 &start 参数。谢谢。
解决方案是在 自定义 SpiceService.class
中覆盖此方法 @Override
protected RestAdapter.Builder createRestAdapterBuilder() {
RestAdapter.Builder builder = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setConverter(getConverter())
.setEndpoint(getServerUrl());
return builder;
}