Home > Uncategorized > How to retrieve Google Backlinks count with PHP

How to retrieve Google Backlinks count with PHP

November 8th, 2009 Leave a comment Go to comments

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 Tags:
  1. November 30th, 2009 at 07:19 | #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. November 30th, 2009 at 13:09 | #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. June 10th, 2010 at 09:06 | #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. August 8th, 2010 at 08:27 | #4

    But that script is only valid if we are talking about one site what would be of fixing it to work for say 50 ?

  5. August 15th, 2010 at 18:43 | #5

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

  6. May 15th, 2011 at 06:58 | #6

    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/&#039 ;) ;
        $response = curl_exec($ch);
        curl_close($ch);
     
        $json = json_decode($response);
        return $json -> responseData -> cursor -> estimatedResultCount;
    }
     
    echo "backlinks=".get_google_backlinks_count('jobsally.com');

  7. May 20th, 2011 at 16:23 | #7

    Change &; to just & in the googleapis.com line.

    Also, you should be passing in YOUR site as the CURLOPT_REFER.

  8. February 13th, 2012 at 14:34 | #8

    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

  1. No trackbacks yet.