尝试使用 Retrofit 通过电影数据库 API 访问内容,但我遇到了崩溃,没有任何抛出的异常或错误消息......我是 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) {
}
});
我在这里做什么?:/
[编辑] 我在端点添加了 / ,并将界面中的方法更改为:
@GET("search/movie")
Call<List<Movie>> getMovieList( @Query("query") String query);
现在的问题是,响应有 body = null,在 rawResponse 中,它有一条消息说 = Response{protocol=http/1.1, code=401, message=Unauthorized, url= https://api.themoviedb.org/ 3/搜索/电影?query=fight%26api_key%-----
我必须设置客户端吗?