【问题标题】:Google API URL return no resultsGoogle API URL 不返回任何结果
【发布时间】:2015-04-21 00:55:54
【问题描述】:

我需要一个 PHP Google 搜索功能,所以我尝试了很多我在 Google 中找到的功能,但几乎所有功能都有相同的问题,即它们直接从 Google 主 URL 而不是 API URL 获取结果,这会在一段时间后导致一个错误,因为 Google 检测到访问来自 PHP 服务器并拒绝任何进一步的请求。

所以我让我的 Google 搜索功能从 Google API URL 获取结果,并且正如您在此处看到的那样完美运行 #API_URL 直到我需要减少结果购买在搜索的关键字之前添加 intitle: ,现在 API URL 根本不返回任何结果,正如您在此处看到的 #API_URL。

我的问题很简单,如何使用此查询在 Google API URL 中获得结果 intitle:maleficent+2014+site:www.anakbnet.com/video/file.php?f=以便我可以使用 PHP 从中获取结果?

【问题讨论】:

  • 你是先注册谷歌,然后注册使用他们的api吗?您可以使用一个 google 搜索 api - 您需要一个 api 密钥并需要阅读他们的文档 - 但您应该能够将该搜索功能无缝集成到您的站点中。你可以找到他们的 api 控制台code.google.com/apis/console
  • 这对我来说已经完成了,我只知道如何使用问题中的 API URL!

标签: php api google-api google-api-php-client google-search-api


【解决方案1】:

您从“Google API”调用返回的数据是 json 编码数据,因此您应该尝试以下操作:-

    /* define a constant for ease */
    define('BR','<br />');


    $data='{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.anakbnet.com/video/file.php?f\u003d1452","url":"http://www.anakbnet.com/video/file.php%3Ff%3D1452","visibleUrl":"www.anakbnet.com","cacheUrl":"http://www.google.com/search?q\u003dcache:9-JgVUvjnGYJ:www.anakbnet.com","title":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل \u003cb\u003e...\u003c/b\u003e","titleNoFormatting":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل ...","content":"29 كانون الثاني (يناير) 2015 \u003cb\u003e...\u003c/b\u003e مشاهدة فيلم \u003cb\u003eMaleficent 2014\u003c/b\u003e DVD HD مترجم اون لاين مباشرة بدون تحميل اكشن ,مغامرة \n,عائلي .. مشاهدة افلام اجنبية مترجمة اونلاين كاملة. (مشاهدة: 491,605 )."}],"cursor":{"resultCount":"1","pages":[{"start":"0","label":1}],
     "estimatedResultCount":"1",
     "currentPageIndex":0,
     "moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den-GB\u0026q\u003dmaleficent+2014+site:www.anakbnet.com/video/file.php?f%3D",
     "searchResultTime":"0.09"}}, 
     "responseDetails": null, 
     "responseStatus": 200}';



   $json=json_decode( $data, true );
   $res=(object)$json['responseData']['results'][0];

   /* two items extracted from data - use same methodology to get other items */
   echo $res->unescapedUrl;
   echo $res->cacheUrl;



    echo '<pre>';
    foreach( $json as $key => $param ){
        echo $key.BR;
        if( is_array( $param )) $param=(object)$param;  
        print_r( $param );
    }
    echo '</pre>';

希望你能从中找到你想要的东西?!

【讨论】:

    猜你喜欢
    • 2012-10-31
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 2016-06-06
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    相关资源
    最近更新 更多