【问题标题】:get google search results stop working 2 days ago让谷歌搜索结果在 2 天前停止工作
【发布时间】:2016-05-11 20:31:15
【问题描述】:

直到 2 天前我的代码 100% 工作

<?php
echo file_get_contents('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Text');
?>

但现在它只显示

{"responseData": null, "responseDetails": "The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)", "responseStatus": 403}

有人知道获得 10 个搜索结果的好方法吗?

我知道它说它不再可用并显示新 api 的链接 .. 但我找不到新 api 的方式来显示旧 API 的结果,只显示来自您的域的结果 我尝试使用 curl 但它不起作用 谢谢!

【问题讨论】:

  • 查看响应详细信息,然后按照建议进行操作。 :D
  • 我看到了,哈哈……但我没有找到替换代码的好方法……

标签: php search-engine file-get-contents google-search


【解决方案1】:

自定义搜索 API 示例 您可以使用 REST 从 JavaScript 调用 JSON/Atom 自定义搜索 API,使用回调查询参数和回调函数。这允许您编写显示自定义搜索数据的丰富应用程序,而无需编写任何服务器端代码。

以下示例使用此方法显示查询汽车的搜索结果的第一页:

<html>
  <head>
    <title>JSON 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=<span class="apiparam">YOUR-KEY</span>&amp;cx=017576662512468239146:omuauf_lfve&amp;q=cars&amp;callback=hndlr">
    </script>
  </body>
</html>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 2023-03-20
  • 2011-05-21
  • 2014-11-02
相关资源
最近更新 更多