1

so I'd wanted to make API call with a dynamic request, but for first, I'd created the "raw" call, hardcoded. So, this address in a web browser works fine

https://api.themoviedb.org/3/discover/movie?api_key=API_KEY&with_genres=27

Here's the raw API call (which is working also)

 @GET("3/discover/movie?api_key=API_KEY&with_genres=27") Call<itemList_model> getHorror();

The problem is when I tried to make the genres to dynamic query. I'm getting error 401 with this, don't know why.

 @GET("3/discover/movie") Call<itemList_model> test(@Query("API_KEY") String key, @Query("with_genres") String[] id); (there's no difference, if I use the array or not, still getting 401)

Retrofit call

   public void getListViewItems() {
     String url = "https://api.themoviedb.org/";
     Retrofit retrofit = new Retrofit.Builder()
           .baseUrl(url)
          .addConverterFactory(GsonConverterFactory.create())
          .build();
     apiCall api = retrofit.create(apiCall.class);
    Call<itemList_model> call = api.test("999ac32d244814bb3415d26876085144", "27");
      call.enqueue(new Callback<itemList_model>() {
     @Override
    public void onResponse(Call<itemList_model> call, Response<itemList_model> response) {
          if (!response.isSuccessful()) {
            Log.i(TAG, "onResponse: " + response.code());
          }
          Log.i(TAG, "onResponse: "+response.code());
      }
       @Override
       public void onFailure(Call<itemList_model> call, Throwable t) {
           Log.i(TAG, "onFailure: " + t.getMessage());
      }
  });
 }

*Error 401: Authentication failed: You do not have permissions to access the service.

Basi
  • 3,009
  • 23
  • 28
  • check the interceptor logs and see what url is generated. – karan Jun 14 '19 at 06:20
  • URL must be like `https://api.themoviedb.org/3/discover/movie?api_key=<>&with_genres=27` so change `test()` method `Query` String – Basi Jun 14 '19 at 06:31

1 Answers1

2

You need to do change like below

change API_KEY to api_key because in your url key is api_key.

@GET("3/discover/movie") Call<itemList_model> test(@Query("api_key") String key, @Query("with_genres") String[] id);
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50