Here's a simple script to retrieve the approximate number of backlinks Google has for a site. The function and how to call it follows:
function get_google_backlinks_count($url) {
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:$url"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.yoursite.com/');
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
return $json ->; responseData ->; cursor -> estimatedResultCount;
}
echo get_google_backlinks_count('yahoo.com');
When running the script I get nothing as a response. I do have an error when trying to manually create the results:
{"responseData": null, "responseDetails": "clip sweeping", "responseStatus": 204}
A quick search on google shows "clip sweeping" means there was something wrong with a passed in parameter. Are you sure the domain you're requesting data for is valid?
In the second line, remove “amp;”, and have something like this:
$url = “http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:$url”;
In my case this change worked.
Congratulations for the script.
Bruno
But that script is only valid if we are talking about one site what would be of fixing it to work for say 50 ?
Roni, you would just iterate through each domain.
Something like this:
$domains = array(‘google.com’, ‘yahoo.com’, ‘msn.com’);
foreach ($domains as $domain)
echo get_google_backlinks_count($domain) . “\n”;
the script does not work for me !! please advice
function get_google_backlinks_count($url) {
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&;q=site:$url";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');
$response = curl_exec($ch);
curl_close($ch);
$json = json_decode($response);
return $json -> responseData -> cursor -> estimatedResultCount;
}
echo "backlinks=".get_google_backlinks_count('jobsally.com');
Change &; to just & in the googleapis.com line.
Also, you should be passing in YOUR site as the CURLOPT_REFER.
Sorry man, but the query used is for indexed pages not backlinks, please check your sources of information.
site:randomtools.net is the operator for indexed pages 🙂
Here you can check the number of backlinks:
http://domof.com/www.randomtools.net.html
… as one can see there are Google Indexed Pages 99 indexed pages and Google Backlinks 84 for this domain on Feb 13, 2012