0
我使用下面的代碼來獲取搜索結果。當我在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);
?>
有沒有什麼辦法可以定義查詢要傳送到哪個數據中心。 – shazia 2011-02-09 08:12:49