图像搜索API bing Retrofit没有得到响应

时间:2017-10-30 15:48:16

标签: android retrofit bing-api

我是翻新的新手.Image Search API获得空响应。虽然响应成功但仍然返回null。

这是进行密钥查询的搜索界面

public interface BingApiService {


@Headers("Ocp-Apim-Subscription-Key: *key*")
@GET("bing/v7.0/search")
Call<ImageSearch> getBingResponse(
         @Query("q") String q


);}

BingApiUtils

public class BingApiUtils {

private BingApiUtils() {
}

public static final String BASE_URL = "https://api.cognitive.microsoft.com/";

public static BingApiService getBingAPIService() {
    return BingRetrofitClient.getClient(BASE_URL).create(BingApiService.class);
}

}

getclient function

public class BingRetrofitClient {

private static Retrofit retrofit = null;

public static Retrofit getClient(String baseUrl) {
    if (retrofit == null) {
        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

}

    bingApiService.getBingResponse("cat").enqueue(new Callback<ImageSearch>() {
        @Override
        public void onResponse(Call<ImageSearch> call, Response<ImageSearch> response) {

 // here I get the null response
        }

        @Override
        public void onFailure(Call<ImageSearch> call, Throwable t) {

        }
    });

1 个答案:

答案 0 :(得分:2)

图片搜索端点似乎不正确。它应该是:https://api.cognitive.microsoft.com/bing/v7.0/images/search。您好像在调用Web搜索API端点。