Reputation: 315
I'm having trouble accessing reddit's json data using retrofit. I've isolated the issue to the timestamp query. Everything works just fine if I take that query out. The strange thing is the link that retrofit is building works fine in the browser, but not in my code.
Would really appreciate help, thank you.
The service class:
@GET("search.json")
Call<ListingsModel> test(@Query("sort") String TOP, @Query("restrict_sr") String RESTRICT_SR,
@Query("limit") int LIMIT,
@Query("q") String q, @Query("syntax") String SYNTAX);
The builder code:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(ApiService.class);
The call in my activity:
Call<ListingsModel> call = service.test(service.TOP, service.RESTRICT_SR, service.LIMIT,
timestamp, service.SYNTAX);
Upvotes: 2
Views: 499
Reputation: 32026
Couple of things with your query --
First not sure if it was cut and paste, but you should not include "&q=" at the beginning, as that will be generated for you.
Second, it looks like you have already url encoded the query string. retrofit/okhttp are going to try to encode it again, which will mess up the query. You have two choices -- do not pass pre-encode, so the query string will look like --
timestamp:338166428..1348009628
, note %3A vs ':'
Or, you can tell retrofit that the query is already encoded and don't encode again by using the encoded
parameter to @Query
@GET("search.json")
Call<ResponseBody> test(@Query("sort") String TOP, @Query("restrict_sr") String RESTRICT_SR,
@Query("limit") int LIMIT,
@Query(value = "q", encoded = true) String q, @Query("syntax") String SYNTAX);
Upvotes: 3