[英]Make a google search from chrome extension
I'm trying to write a simple chrome extension which will take input from a textbox and do a google image search and show the results in the extension's window.我正在尝试编写一个简单的 chrome 扩展程序,它将从文本框中获取输入并进行谷歌图像搜索并在扩展程序的窗口中显示结果。
I've tried using a GET form but that doesn't seem to be working at all.我试过使用 GET 表单,但这似乎根本不起作用。 I'm trying to get their JSAPI (from https://developers.google.com/web-search/docs/?hl=en ) and I'm getting the error "Cannot read property 'ImageSearch' of undefined" in the console.
我正在尝试获取他们的 JSAPI(来自https://developers.google.com/web-search/docs/?hl=en )并且在安慰。
Google seems to want me to use their custom search engine (CSE) function but it's not a website I'm doing this from it's an extension. Google 似乎希望我使用他们的自定义搜索引擎 (CSE) 功能,但它不是一个网站,我从它的扩展程序中执行此操作。
Instead of using the Custom Search Engine with its builder, you can use the Custom Search API , which is a customizable extension of the Custom Search Engine.您可以使用自定义搜索 API ,而不是使用自定义搜索引擎及其构建器,它是自定义搜索引擎的可自定义扩展。
Also, a Google Chrome extension is basically a webpage with access to additional APIs and functionality (especially limited control over the user's browsing experience).此外,Google Chrome 扩展程序基本上是一个可以访问其他 API 和功能的网页(尤其是对用户浏览体验的有限控制)。
EDIT (Dec 22, 2020): As of Oct 24, 2016 it seems like Google stopped supporting their Custom Search API linked above.编辑(2020 年 12 月 22 日):截至 2016 年 10 月 24 日,Google 似乎停止支持上面链接的自定义搜索 API。 Refer to the updated Programmable Search Element Control API v2 , which functions differently but should still answer the original question.
请参阅更新的Programmable Search Element Control API v2 ,其功能不同但仍应回答原始问题。
Relevant snippet demonstrating basic usage of the new API, modified from the linked page:相关代码片段演示了新 API 的基本用法,从链接页面修改:
<!-- Put the following javascript before the closing </head> tag and replace 123:456 with your own Programmable Search Engine ID. --> <!-- NOTE: I've replaced "123:456" with the example ID from the documentation page --> <script async src="https://cse.google.com/cse.js?cx=000888210889775888983:y9tkcjel090"></script> <!-- Place this tag where you want both of the search box and the search results to render --> <div class="gcse-search"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.