Java:Android:Retrofit - 使用Call但响应{code = 401,message = unauthorized}

时间:2015-10-20 23:09:43

标签: java android retrofit retrofit2

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

我必须建立一个客户端吗?

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:-1)

我想出了我做错了什么,我正在制作的请求的结果,在json中提供了更多的对象......只需创建一个包含所述字段的对象,并使用List。

相关问题