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:

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');

8 thoughts on “How to retrieve Google Backlinks count with PHP”

  1. 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}

  2. 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?

  3. 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

  4. 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”;

  5. 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');

  6. 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

Leave a Reply

Your email address will not be published. Required fields are marked *