首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在浏览器中使用Google search API

问在浏览器中使用Google search API
EN

Stack Overflow用户
提问于 2012-06-30 20:26:13
回答 2查看 5.8K关注 0票数 1

有没有好的客户端JS库来访问Google的搜索API?

EN

回答 2

Stack Overflow用户

发布于 2012-06-30 20:31:14

我发现了一个很好的例子,如何在客户端使用Google Custom Search API。从文档中:

代码语言:javascript
复制
<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的回调函数。

票数 2
EN

Stack Overflow用户

发布于 2012-06-30 20:29:05

试用谷歌搜索应用程序接口https://developers.google.com/web-search/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11274056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档