谷歌AJAX搜索API不returnig结果

问题描述:

我使用下面的代码来获取搜索结果。当我在google中插入字符串时,我得到一个搜索结果,但是当我试图通过代码获取结果时,它不返回任何结果。任何人都可以解释为什么代码无法正常工作。如果我进入其他一些搜索词谷歌AJAX搜索API不returnig结果

<?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); 
    ?> 

你的代码是正确的,它返回的结果。它会调用API并获得响应。

如果您进行了其他搜索,比如说“数码相机”,结果就是该响应的一部分。

为什么API返回的结果与Google的数十个数据中心不同?您的网络搜索的回报率只有Google或Google的文档能够回答。

+0

有没有什么办法可以定义查询要传送到哪个数据中心。 – shazia 2011-02-09 08:12:49