0

尝试使用 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%-----

我必须设置客户端吗?

4

2 回答 2

0

好的,我可以看到你的问题,搜索应该是这样的:

http://api.themoviedb.org/3/search/movie?api_key=###&query=iron sky

所以,问题是你是如何形成 URL 的。

于 2015-10-21T00:33:31.983 回答
-2

我想出了我做错了什么,我提出的请求的结果,在 json 中提供了更多对象......只需创建一个具有所述字段和列表的对象。

于 2015-10-21T11:39:02.150 回答