2010-08-08 156 views

回答

5

您更改索引:

要遍歷所有:

foreach ($x->responseData->results as $r) { 
    echo $r->url, "\n"; 
} 

您可以使用var_dump($x);檢查完整結果。

要檢索結果的另一頁,您可以使用start參數,例如:

$x = json_decode(
    file_get_contents(
    'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&start=4&q=' 
    . urlencode($search))); 

您可以要求8分的結果,而不是4 rsz=large

+0

它顯示結果..在腳本中。它只會顯示約4個結果。 我想知道的是如何在下一頁顯示結果 – kapitanluffy 2010-08-09 00:01:03

+0

ohai謝謝:) 我其實已經做到了。閱讀'start = 4'後,我開悟了 我做的是'start = 1',其中currentpageindex仍然是0哈哈xD – kapitanluffy 2010-08-09 00:09:53

+0

以下是文檔http://code.google.com/apis/ajaxsearch/documentation/#fonje – 2010-08-09 00:10:33

1

爲別人尋求與谷歌的接口,並無意中發現了這個解決方案,上面現在的代碼返回這樣的響應:object(stdClass)#1 (3) { ["responseData"]=> NULL ["responseDetails"]=> string(143) "The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)" ["responseStatus"]=> int(403) }

請遷移到谷歌自定義搜索API(https://developers.google.com/custom-search/我希望這樣可以節省別人一些時間!