如何使用JAVA来使用Google Custom Search API? Google Search Appliance API的适当用途是什么?Google Custom Search API
1
A
回答
3
这里是谷歌自定义搜索API示例。你需要下载库和示例如下
public class Custom {
public static void main(String args[]) throws IOException {
String key="Replace with your API key";
String qry="batman";// search key word
URL url = new URL(
"https://www.googleapis.com/customsearch/v1?
key="+key+"&cx="Replace with unique ID"&q="+ qry +
"&alt=json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println(url);
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
if(output.contains("\"link\": \"")){
String link=output.substring(output.indexOf("\"link\": \"")+
("\"link\": \"").length(), output.indexOf("\","));
System.out.println(link);
}
}
conn.disconnect();
}
}
+0
我得到403响应代码 – Jyothish
+0
403是由于API密钥。您需要从Google开发者控制台创建一个新的 –
相关问题
- 1. Google Custom Search API C#2.0
- 2. Google Custom Search with mod_rewrite search term
- 3. Google Custom Search Accessibility
- 4. Google Custom Search in Cyrillic
- 5. Google Custom Search Style Issues
- 6. Google Custom Search API自动完成?
- 7. C#中的Google Custom Search API:寻呼
- 8. Google Custom Search。直接回答
- 9. 在Google中使用Google Custom Search API google-api-client
- 10. Google Custom Search分页问题
- 11. Google Custom Search Engine:“messy”query URL
- 12. Google Custom Search will not preview
- 13. Google Custom Search热门查询为xml?
- 14. Google Custom Search仅返回“无结果”
- 15. Google Custom Search Engine and Bootstrap3 Style issue
- 16. Google Custom Search排序属性问题
- 17. Google Custom Search Element:造型广告
- 18. Google Search API ruby
- 19. Google API for Search
- 20. 如何使用Google Custom Search API for .NET进行搜索?
- 21. Google Custom Search API问题:最多100条查询
- 22. GOOGLE CUSTOM SEARCH API - (与功能相关的搜索)
- 23. Google Search API for C#
- 24. Google Custom Search - 与注释标签相关的同义词
- 25. 查询Google Search Console API PHP
- 26. Google Site Search XML API分页
- 27. Google Goggles或Visual Search的API?
- 28. Google Search Console API多维度
- 29. 在Google Custom Search中绑定单击事件以'搜索'按钮
- 30. Google Custom Search(CSE)API返回错误代码500({“error”:{“code”:500,“message”:null}})
真的含糊不清的问题... –