2011-02-09 15 views
0

私は以下のコードを使用して検索結果を取得しています。私はGoogleに文字列を挿入するとき、私は1つの検索結果を得るが、私はコードを介して結果を取得しようとしているときに何も返しません。コードが動作しない理由を誰もが説明することができます。他の検索語を入力すると結果が返されますGoogle AJAX Search API not 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); 
    ?> 

答えて

0

コードは問題ありません。 API呼び出しを行い、応答を取得します。

"デジタルカメラ"などの別の検索を行うと、結果はその応答の一部です。

ウェブ検索で返されるGoogleの何十億ものデータセンターとは異なる結果が返ってくる理由は、GoogleまたはGoogleのドキュメントのみが回答できる質問です。

+0

私はクエリがどのデータセンターに行くかを定義することができます。 – shazia

+0

いいえ誰もどこにいるのか、どこにいるのかは分かりません!ポイントは、常に同じ検索結果を得ることに頼ることができないということです。 –

関連する問題