0

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}
LeteciTanjir
  • 106
  • 10
  • how does the code look like that does the request and prints it? http://stackoverflow.com/questions/22325641/retrofit-callback-get-response-body suggests that printing `Response` may omit the response body unless you set debug mode – zapl Nov 13 '15 at 02:18
  • @zapl That request and response are straight out of the Android Studio debugger. – LeteciTanjir Nov 13 '15 at 02:21

1 Answers1

0

I have managed to figure out my problem; a lack of sleep. The ImgurResponse that I am using to de-serialize the JSON that I get back from the Imgur API was not correct. The response that I get back contains success, status, and data with data containing the information that I was looking to parse. Didn't realize my mistake because of the "raw response" from the debugger not containing the actual response from the API.

LeteciTanjir
  • 106
  • 10