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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.