gpt4 book ai didi

java - 改造 - 调用中的参数无效

转载 作者:行者123 更新时间:2023-12-02 04:31:03 29 4
gpt4 key购买 nike

我刚刚从响应中获取代码,它说我的请求参数错误,那么我的 api 调用应该是什么样子?

这是来自文档的硬编码 API 调用

https://api.themoviedb.org/3/discover/movie?api_key=[API_KEY]&with_genres=27

这是我的 API 调用

@GET("3/search/movie")
Call<itemList_model> test(@Query("api_key") String key,@Query("with_genres") int query);

代码

    Invalid parameters: Your request parameters are incorrect.

改造电话

public void getListViewItems() {
String url = "https://api.themoviedb.org/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();

apiCall api = retrofit.create(apiCall.class);
Call<itemList_model> call = api.test("API_KEY",27); <- 27 stand's for horror genres.
call.enqueue(new Callback<itemList_model>() {
@Override
public void onResponse(Call<itemList_model> call, Response<itemList_model> response) {
if (!response.isSuccessful()) {
Log.i(TAG, "onResponse: " + response.code());
}
Log.i(TAG, "onResponse: "+response.code());
}
@Override
public void onFailure(Call<itemList_model> call, Throwable t) {
Log.i(TAG, "onFailure: " + t.getMessage());
}
});
}

最佳答案

简单的错字。应该是:

https://api.themoviedb.org/3/discover/movie?api_key=[API_KEY]&with_genres=27

但是:

https://api.themoviedb.org/3/search/movie?api_key=[API_KEY]&with_genres=27

工作代码

package test;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

public interface RetrofitProxy {

@GET("3/discover/movie")
Call<Object> test(@Query("api_key") String apiKey, @Query("with_genres") int genreCode);
}


package test;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.io.IOException;

public class RetrofitTest {

public static void main(String[] args) throws IOException {
String url = "https://api.themoviedb.org/";

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();

RetrofitProxy retrofitProxy = retrofit.create(RetrofitProxy.class);
Call<Object> call = retrofitProxy.test("API_KEY", 27);

Response<Object> execute = call.execute();
System.out.println(execute.raw());
System.out.println(execute.isSuccessful());
System.out.println(execute.body());
}
}

关于java - 改造 - 调用中的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56585263/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com