【发布时间】:2016-01-19 19:17:49
【问题描述】:
尝试使用 Retrofit 通过电影数据库 API 访问内容,但我遇到了崩溃,没有任何抛出的异常或错误消息...我是 Retrofit 的新手,但我搜索了一些文档,这就是我有(我正在使用 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 中,它有一条消息说 = 响应{protocol=http/1.1, code=401, message=Unauthorized, url=https://api.themoviedb.org/3/search/movie?query=fight%26api_key%-----
我必须设置客户端吗?
【问题讨论】:
-
但是错误是什么,有些异常?请添加更多信息,您是否设置了正确的权限?互联网许可?
-
是的,我有互联网权限
-
好吧,我认为您需要在提出要求之前进行测试,我通常使用 Postman 来完成该任务,我明确要求然后可以进行改造。 chrome.google.com/webstore/detail/postman/…
-
好的,很酷,我试过了,效果很好
标签: java android retrofit retrofit2