trying to use Retrofit to access stuff, with themoviedatabase API, but i'm getting a crash, without any thrown exception or error message... I'm new to Retrofit, but i searched some documentation, and this is what i have(i'm using the Retrofit 2.0):
String movieToSearch = "fight";
String ENDPOINT = "https://api.themoviedb.org/3";
String API_KEY = "&api_key=------------------------------";
Retrofit adapter = new Retrofit.Builder()
.baseUrl(ENDPOINT)
.addConverterFactory(GsonConverterFactory.create())
.build();
TMDBAPI apiService = adapter.create(TMDBAPI.class);
String query = movieToSearch + API_KEY;
Call<List<Movie>> call = apiService.getMovieList(query);
call.enqueue(new Callback<List<Movie>>() {
@Override
public void onResponse(Response<List<Movie>> response, Retrofit retrofit) {
List<Movie> movieList = (response.body());
}
@Override
public void onFailure(Throwable t) {
}
});
What am i doing worng here? :/
[EDIT] i added a / to the end point, and changed the method in the interface to this: @GET("search/movie") Call<List<Movie>> getMovieList( @Query("query") String query);
the problem now is, the response has body = null, in the rawResponse, it has a message saying = Response{protocol=http/1.1, code=401, message=Unauthorized, url= https://api.themoviedb.org/3/search/movie?query=fight%26api_key%-----
do i have to set up a client?
Ok, I can see your problem, the search should be do like this:
http://api.themoviedb.org/3/search/movie?api_key=###&query=iron sky
So, the problem is how are you forming the URL.
我想出我做错了什么,我提出的请求结果,在json中提供了更多对象...只需创建一个具有所述字段和List的对象即可。
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.