I have used an another test API and it is work fine, but here when I use the actual API with my KEY it is not getting any data.
My APIService
public interface APIServiceTop {
@GET("v2/top-headlines")
Call<List<ArticlesModel>> getTopObjectsList(
@Query("country")
String countryCode,
@Query("page")
int pageNumber,
@Query("apikey")
String API_KEY
);
}
My RetroInstance
public class RetroInstance {
public static String BASE_URL = "https://newsapi.org/";
private static Retrofit retrofit;
public static HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
public static Retrofit getRetroClientTop() {
logging.level(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(logging)
.build();
if(retrofit == null ) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
}
return retrofit;
}
and here's a link from document, I made like what they wrote. document