How to retrieve Google Backlinks count with PHP
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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'); |
Categories: Uncategorized
![[del.icio.us]](http://www.randomtools.net/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.randomtools.net/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://www.randomtools.net/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.randomtools.net/wp-content/plugins/bookmarkify/google.png)
![[Reddit]](http://www.randomtools.net/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.randomtools.net/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://www.randomtools.net/wp-content/plugins/bookmarkify/stumbleupon.png)
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.