Android 无法在call.enque()中的改装中获得响应
我正在从Shopify中配对Android 无法在call.enque()中的改装中获得响应,android,android-studio,retrofit,retrofit2,shopify-app,Android,Android Studio,Retrofit,Retrofit2,Shopify App,我正在从Shopify中配对CollectionListingApi,我需要将'CollectionListing\u id'作为url中的参数传递。我正在传递id,但无法在回调中获得响应 注意:我已经在Postman中使用参数测试了api,效果很好 这是我的实现 ProductActivity.java private void processProductIds() { apiInterface = APIClient.getClient().create(ApiInterfac
CollectionListing
Api,我需要将'CollectionListing\u id'
作为url
中的参数传递。我正在传递id,但无法在回调中获得响应
注意:我已经在Postman中使用参数测试了api,效果很好
这是我的实现
ProductActivity.java
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<List<Integer>> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<List<Integer>>() {
@Override
public void onResponse(Call<List<Integer>> call, Response<List<Integer>> response) {
String s = String.valueOf(response.body());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<List<Integer>> call, Throwable t) {
}
});
}
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<List<Integer>> getProductIds(@Header("Authorization") String accessToken, @Path("collection_listing_id") long id);
}
谢谢。您需要将
getProductId
的返回类型从Call
更改为Call
编辑:(如评论中所述)
您还应该将
List productIds
更改为List productIds
您需要将getProductIds
的返回类型从Call
更改为Call
编辑:(如评论中所述)
您还应该将List productid
更改为List productid
尝试使用
mAPIService.functionpost("url/"+id).enqueue(new Callback<List<IdExample>>() {
@Override
public void onResponse(Call<List<IdExample>> call, Response<List<IdExample>> response) {
if (response.isSuccessful()) {
if (constantsVariables.debug) {
Log.i(constantsVariables.TAG, "/****************************/" + response.raw());
}
}
@Override
public void onFailure(@NonNull Call<List<IdExample>> call, @NonNull Throwable tr) {
Log.d("TEST Inside fail if", Log.getStackTraceString(tr));
}
});
mAPIService.functionpost(“url/”+id).enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
if(constantsVariables.debug){
Log.i(constantsVariables.TAG,“/*****************************/”+response.raw());
}
}
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable tr){
Log.d(“如果内部测试失败”,Log.getStackTraceString(tr));
}
});
尝试使用
mAPIService.functionpost("url/"+id).enqueue(new Callback<List<IdExample>>() {
@Override
public void onResponse(Call<List<IdExample>> call, Response<List<IdExample>> response) {
if (response.isSuccessful()) {
if (constantsVariables.debug) {
Log.i(constantsVariables.TAG, "/****************************/" + response.raw());
}
}
@Override
public void onFailure(@NonNull Call<List<IdExample>> call, @NonNull Throwable tr) {
Log.d("TEST Inside fail if", Log.getStackTraceString(tr));
}
});
mAPIService.functionpost(“url/”+id).enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
if(constantsVariables.debug){
Log.i(constantsVariables.TAG,“/*****************************/”+response.raw());
}
}
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable tr){
Log.d(“如果内部测试失败”,Log.getStackTraceString(tr));
}
});
应该是这样的
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<IdExample> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<IdExample>() {
@Override
public void onResponse(Call<IdExample> call, Response<IdExample> response) {
String s = String.valueOf(response.body().getProductIds());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<IdExample> call, Throwable t) {
}
});
}
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<IdExample> getProductIds(@Header("Authorization") String
accessToken, @Path("collection_listing_id") long id);
}
private void processProductIds(){
apinterface=APIClient.getClient().create(apinterface.class);
Call Call=apinterface.getProductId(key,id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
String s=String.valueOf(response.body().getProductId());
Log.d(“S”,“onResponse:+S”);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});
}
然后像这样更改api接口
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<IdExample> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<IdExample>() {
@Override
public void onResponse(Call<IdExample> call, Response<IdExample> response) {
String s = String.valueOf(response.body().getProductIds());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<IdExample> call, Throwable t) {
}
});
}
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<IdExample> getProductIds(@Header("Authorization") String
accessToken, @Path("collection_listing_id") long id);
}
公共接口{
@GET(“collection_listings/{collection_listing_id}/product_id.json”)
调用getProductId(@Header(“Authorization”)字符串
accessToken,@Path(“集合列表id”)长id);
}
应该是这样的
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<IdExample> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<IdExample>() {
@Override
public void onResponse(Call<IdExample> call, Response<IdExample> response) {
String s = String.valueOf(response.body().getProductIds());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<IdExample> call, Throwable t) {
}
});
}
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<IdExample> getProductIds(@Header("Authorization") String
accessToken, @Path("collection_listing_id") long id);
}
private void processProductIds(){
apinterface=APIClient.getClient().create(apinterface.class);
Call Call=apinterface.getProductId(key,id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
String s=String.valueOf(response.body().getProductId());
Log.d(“S”,“onResponse:+S”);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});
}
然后像这样更改api接口
private void processProductIds() {
apiInterface = APIClient.getClient().create(ApiInterface.class);
Call<IdExample> call = apiInterface.getProductIds(key, id);
call.enqueue(new Callback<IdExample>() {
@Override
public void onResponse(Call<IdExample> call, Response<IdExample> response) {
String s = String.valueOf(response.body().getProductIds());
Log.d("S", "onResponse:" + s);
}
@Override
public void onFailure(Call<IdExample> call, Throwable t) {
}
});
}
public interface ApiInterface {
@GET("collection_listings/{collection_listing_id}/product_ids.json")
Call<IdExample> getProductIds(@Header("Authorization") String
accessToken, @Path("collection_listing_id") long id);
}
公共接口{
@GET(“collection_listings/{collection_listing_id}/product_id.json”)
调用getProductId(@Header(“Authorization”)字符串
accessToken,@Path(“集合列表id”)长id);
}
您所说的“无法获得响应”是什么意思?onResponse
回调根本没有被调用?或者它被调用但响应为空?@y.allam无法在回调中获得响应。在postman中测试时,api工作正常。您所说的“无法获得响应”是什么意思“onResponse
回调根本没有被调用?或者它被调用,但响应为空?@y.allam无法在回调中获得响应。在postman中测试时,api工作正常。我尝试了…它不工作。事实上,我首先实现了这一点。这是我在onFailure()中收到的消息。”在日志“Error Failure:onFailure:java.lang.NumberFormatException:应为int,但在第1行第30列路径$.product_id[0]处为13301092619350”整数是一个32位的数字,最大值是2147483647。你应该用长的时间来精确地得到这个问题。我会做出改变并尝试。这就说明了为什么你应该在问题中显示你的研究,以及为什么你应该总是考虑代码中的错误分支。我试过……它不起作用。事实上,我在一开始就实现了这一点。是日志“Error Failure:onFailure:java.lang.NumberFormatException:应为int,但在第1行第30列path$.product_ID[0]处为1331092619350”中的onFailure()中收到的消息整数是一个32位的数字,最大值是2147483647。你应该用长的时间来精确地得到这个问题。我会做出改变并尝试。这就说明了为什么你应该在问题中显示你的研究以及为什么你应该总是考虑代码中的错误分支。