Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Bing Web search fails with Query search

Tags:

azure

bing

I am using the Odata4j. When i try to execute for simple Web search with my query, getting following exeception at last line of the code:

PS: Please voteup if you find this helpful.Thanks

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();
like image 538
FindIt Avatar asked Dec 09 '22 07:12

FindIt


1 Answers

Not much into Java, but I've just got the same error with the implementation for Node.js, and the problem was that I forgot to add single quotes around the query. It should be something like:

...&Query='stackoverflow'

so after the URL encoding we have something like:

...&Query=%27stackoverflow%27

At least that worked for me.

like image 84
Mr. Goferito Avatar answered Dec 10 '22 21:12

Mr. Goferito