有没有好的客户端JS库来访问Google的搜索API?
发布于 2012-06-30 20:31:14
我发现了一个很好的例子,如何在客户端使用Google Custom Search API。从文档中:
<html>
<head>
<title>JSON/Atom Custom Search API Example</title>
</head>
<body>
<div id="content"></div>
<script>
function hndlr(response) {
for (var i = 0; i < response.items.length; i++) {
var item = response.items[i];
// in production code, item.htmlTitle should have the HTML entities escaped.
document.getElementById("content").innerHTML += "<br>" + item.htmlTitle;
}
}
</script>
<script src="https://www.googleapis.com/customsearch/v1?key=YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=cars&callback=hndlr">
</script>
</body>
</html>您必须将API密钥定义为
你的钥匙
和您的查询条件,如
q=cars
参数,结果将通过定义的javascript函数"hndlr()“加载到"content”div中,该函数是来自Google API的回调函数。
发布于 2012-06-30 20:29:05
试用谷歌搜索应用程序接口https://developers.google.com/web-search/
https://stackoverflow.com/questions/11274056
复制相似问题