Google API URL不返回结果


Google API URL return no results

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

因此,我让我的谷歌搜索功能从谷歌API URL中获取结果,正如你在这里看到的那样,这非常有效#API_URL,直到我需要减少结果购买,在搜索关键字之前添加标题:,现在API URL根本不返回结果,就像你在这里所看到的那样#API_URL。

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

您从‘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>';

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