I have to create a web application. First, I have to use the Google Search API. I tested the free Google Search API which gives 100 requests per day, but I have some problems: The results obtained are not identical to navigation in Google and if I search, for example, "The best universities" without space, it gives me this error:
java.io.IOException: Server returned HTTP response code: 400 for URL: https://www.googleapis.com/customsearch/v1?key=XXXX&cx=013036536707430787589:_pqjad5hr1a&q=the best universities&alt=json&num=10&start=1
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
But if I type "The_best_universities" or "The+best+universities" it works normally. Here is my query string:
String toSearch = "https://www.googleapis.com/customsearch/v1?key=" + apiKey + "&cx=013036536707430787589:_pqjad5hr1a&q="+ customSearchEngineKey + "&alt=json";