2017-10-25 3 views
0

Ich muss eine Webanwendung erstellen. Zuerst muss ich das Google Search API verwenden. Ich habe das kostenlose Google-Such-API getestet, das 100 Anfragen pro Tag liefert, aber ich habe einige Probleme: Die erzielten Ergebnisse sind nicht identisch mit der Navigation in Google und wenn ich zum Beispiel "Die besten Universitäten" ohne Platz suche, gibt es mir das Fehler:API Google Suche

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) 

Aber wenn ich "The_best_universities" oder "The + Best + Universitäten" eingeben, funktioniert es normal. Hier ist meine Abfrage-String:

String toSearch = "https://www.googleapis.com/customsearch/v1?key=" + apiKey + "&cx=013036536707430787589:_pqjad5hr1a&q="+ customSearchEngineKey + "&alt=json"; 

Antwort

0

URL kodieren Ihre Parameter

java.net.URLEncoder.encode(customSearchEngineKey, "UTF-8"); 
+0

Vielen Dank für Ihre Antwort. –