So I am working on an Android app and I have decided to use Retrofit 2.0 for all my HTTP requests to the various APIs that I require. I have run into an issue that I have not been able to debug, which is that when I send a request for image information using an image ID, I am just getting a 200 response with the link where I sent my GET request. Using Postman, I get the response that I am looking for (which is the Imgur image data model JSON: https://api.imgur.com/models/image) but I can't seem to get it working with Retrofit.
Below I have attached service class and the request + response. Any information or brainstorming is greatly appreciated :)
The interface:
public interface ImgurService
{
@GET("Image/{id}")
Call<ImgurResponse> getImageInfo(@Path("id") String id);
}
The service class instance:
public static ImgurService getInstance()
{
if (IMGUR_SERVICE == null) {
Interceptor interceptor = new Interceptor()
{
@Override
public Response intercept(Chain chain) throws IOException
{
Request newRequest = chain.request().newBuilder().addHeader("Authorization", CLIENT_ID).build();
return chain.proceed(newRequest);
}
};
OkHttpClient client = new OkHttpClient();
client.interceptors().add(interceptor);
Retrofit RETROFIT = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
IMGUR_SERVICE = RETROFIT.create(ImgurService.class);
}
return IMGUR_SERVICE;
}
The request:
Request{method=GET, url=https://api.imgur.com/3/Image/CgZzfSd, tag=Request{method=GET, url=https://api.imgur.com/3/Image/CgZzfSd, tag=null}}
The raw response:
Response{protocol=http/1.1, code=200, message=OK, url=https://api.imgur.com/3/Image/CgZzfSd}