for keyword selection (seo)I need to know only the number of results for specific group of keywords. got this code from google https://developers.google.com/web-search/docs/), but no way. PHP version is 5.6
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=relax&userip=MYIP";
$referrer = "http://localhost:8080/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
in this case ... no results at all
I tried other ways ... eg.:
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=relax";
$body = file_get_contents($url);
$json = json_decode($body);
$results= $json->responseData->cursor->resultCount;
in this case I got some schizophrenic results (sometimes I got numbers, sometimes I got nothing)... in any case always under the declared limit of 1000. any suggestion? Thanks in advance.
As the AJAX Api is now deprecated, you can use a third party service like Serp Api to get Google results.
It should be easy to integrate:
$query = [
"q" => "Coffee",
"google_domain" => "google.com",
];
$serp = new GoogleSearchResults();
$json_results = $serp.json($query);