Azure Bing Web Search with Query Search

I am using Odata4j. When I try to run for a simple web search with my query, getting the following exeception in the last line of code:

PS: Please vote if you find this helpful. thank

java.lang.RuntimeException: Expected status OK, found Bad Request. Server response:
Parameter: Query is not of type String
    at org.odata4j.jersey.consumer.ODataJerseyClient.doRequest(ODataJerseyClient.java:165) 

This is my code:

ODataConsumer consumer = ODataConsumers
                .newBuilder("https://api.datamarket.azure.com/Bing/Search/v1/")
                .setClientBehaviors(OClientBehaviors.basicAuth("accountKey", "My account key here"))
                .build();


  System.out.println(consumer.getServiceRootUri()+consumer.toString());

  OQueryRequest<OEntity> oQueryRequest = consumer.getEntities("Web").custom("Query", "Search text criteria");


    System.out.println("oRequest"+oQueryRequest);

        Enumerable<OEntity> entities  = oQueryRequest.execute();
+4
source share
1 answer

Not much in Java, but I just got the same implementation error for Node.js, and the problem is that I forgot to add single quotes around the request. It should be something like:

...&Query='stackoverflow'

so after url coding we have something like:

...&Query=%27stackoverflow%27

At least it worked for me.

+14
source

Source: https://habr.com/ru/post/1543547/


All Articles