【发布时间】:2017-10-25 15:50:10
【问题描述】:
我必须创建一个 Web 应用程序。首先,我必须使用 Google Search API。我测试了每天提供 100 个请求的免费 Google 搜索 API,但我有一些问题:获得的结果与 Google 中的导航不同,如果我搜索,例如,没有空格的“最好的大学”,它给了我这个错误:
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)
但如果我输入“The_best_universities”或“The+best+universities”,它会正常工作。这是我的查询字符串:
String toSearch = "https://www.googleapis.com/customsearch/v1?key=" + apiKey + "&cx=013036536707430787589:_pqjad5hr1a&q="+ customSearchEngineKey + "&alt=json";
【问题讨论】:
标签: java json google-search-api