【问题标题】:Google AJAX Search API not returnig resultsGoogle AJAX 搜索 API 未返回结果
【发布时间】:2011-02-09 06:45:58
【问题描述】:

我正在使用下面的代码来获取搜索结果。当我在谷歌中插入字符串时,我得到一个搜索结果,但是当我试图通过代码获取结果时,它什么也不返回。谁能解释为什么代码不起作用。如果我输入其他搜索词,它会返回结果

 <?php
    $string="make them see things from your view";
     $request =  trim("http://ajax.googleapis.com/ajax/services/search/web");
      $referrer = trim("http://localhost/"); 

      $version = "1.0";
       $getargs = '?v='. $version .'&rsz=small&q="'. urlencode($string).'"' ;

      // Get the curl session object
      $session = curl_init($request . $getargs);
      // Set the GET options.
      curl_setopt($session, CURLOPT_HTTPGET, true);
      curl_setopt($session, CURLOPT_HEADER, true);
      curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($session, CURLOPT_REFERER, $referrer);

     //var_dump $response;
      $response=null;
      // Do the POST and then close the session
      $response = curl_exec($session);
      curl_close($session);
    var_dump ($response);
      // Get HTTP Status code from the response
      $status_code = array();
preg_match('/\d\d\d/', $response, $status_code);
    print_r($status_code);
    ?>

【问题讨论】:

    标签: php search


    【解决方案1】:

    您的代码很好。它进行 API 调用并获得响应。

    如果您进行不同的搜索,例如“数码相机”,则结果是该响应的一部分。

    为什么 API 返回的结果与 Google 的数十个数据中心为您的网络搜索返回的结果不同,这个问题只有 Google 或 Google 的文档才能回答。

    【讨论】:

    • 有什么方法可以定义查询去往哪个数据中心。
    • 没有。甚至没有人确切知道它们有多少以及它们的位置!关键是您不能依赖始终获得相同的搜索结果。
    猜你喜欢
    • 1970-01-01
    • 2020-08-30
    • 2016-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多