我正在为我的网站使用 Google 搜索 API。
除一个搜索查询外,所有搜索查询一切正常!
包含 site:noviniran.com
的查询不返回任何结果!!!!
我不知道为什么!此查询适用于普通 Google.com,但在 Google Search API 上不会返回任何内容。
查看:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:noviniran.com
其他查询返回没有问题的结果:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:iran.com
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:iranair.com
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:irannovin.com
我一岁的网站怎么了? :(
抱歉英语不好,
提前谢谢
最佳答案
正如我现在测试的那样,它响应 Google Web Search API 不再可用。请迁移到 Google 自定义搜索 API
。因此,我将尽力举例说明自定义搜索 api
的工作原理。
function getData(query, engine, search_key) {
/*
Info about google custom search API:
The first 100 queries per day are free.
Any more, then you have to pay $5 per 1000 queries, for up to 10,000 queries per day,
just enable billing to do so. Each query returns a maximum of 10 results,
so you can retrieve 1000 URL’s from your search per day for free.
*/
var API_KEY = search_key;
var ENGINE_ID = engine;
var API_URL = `https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${ENGINE_ID}&searchType=image&q=${query}`;
jQuery.getJSON(API_URL, {
tags: query,
tagmode: "any",
format: "json"
},
function(data) {
//do something
});
}
<div id="image" onload="getData("your_search", "your_engine_id", "your_key")"></div>
但在运行此代码段之前,请首先在 Google 上为此创建一个 API key
以及一个您需要它的 ID
的自定义搜索引擎
。此外,在创建自定义引擎
后,您需要启用图像搜索
选项。
当您创建它时,您需要确保您有一个字符串构建,其中请求api key
和搜索引擎ID
,如下所示:
https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${ENGINE_ID}&searchType=image&q=${query}
第二部分是您需要将字符串设置到 getJSON
中,因为您希望从该搜索中获取数据,如下所示:
jQuery.getJSON(API_URL, {
tags: query,
tagmode: "any",
format: "json"
},
最后你想要一个函数来关闭json
,这样你就可以对数据做任何你想做的事情,如下所示:
function(data) {
//do whatever
});
请记住,这只是一个示例,可帮助您进一步推进项目。
关于javascript - Google Ajax 搜索 API 没有来自网站 :mywebsite. com 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22690311/