Google AJAX Search API not returnig results
I am using the code below to get search results. When I insert the string in google i get one search result but when i am trying to get result through code it returns nothing. Can anyone explain 开发者_JS百科why the code is not working. It returns results if i enter some other search term
<?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);
?>
Your code is fine. It makes the API call and gets the response.
If you make a different search, say, "digital cameras", results are part of that response.
Why the API returns different results than whatever of Google's dozens of data centers returns for your web search is a question only Google, or Google's documentation, can answer.
精彩评论