tags:

views:

163

answers:

3

hi

i want to create my own tool for back-links calculation using PHP. is there any api to fetech the data for back links

+1  A: 

Run a Google search with the URL prefixed by link: - for instance, link:www.mydomain.com.

While Google does provide a more specific backlink overview in their Webmaster Tools area (more info), I'm not sure they provide an external API for it.

Amber
but how can i use it in my PHP code ?
vipinsahu
Use the Google Search AJAX API: http://code.google.com/apis/ajaxsearch/documentation/#fonje
Amber
+1  A: 

since the question is "how to use in php code?" I assume you want to process on the server side as opposed to ajax on the client side. So use the Google URL link: hack in combination with curl http://php.net/manual/en/book.curl.php

RandyMorris
JSON is not limited to AJAX. You can also parse JSON with PHP, Dav's link contains an example.
Arda Xi
I am not saying it is, was clarifying to the op that can be used server side. I think the important part was using curl which you gladly took from my response.
RandyMorris
Actually, that came from the API dav linked. Everything but the foreach was copied from there.
Arda Xi
+1  A: 

The full implementation in PHP would look something like this:

<?php
$domain = "example.com"; // Enter your domain here.

$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;rsz=large&amp;"
    . "q=link:".$domain;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $domain);
$body = curl_exec($ch);
curl_close($ch);

$json = json_decode($body);
$urls = array();
foreach($json->responseData->results as $result) // Loop through the objects in the result
    $urls[] = $result->unescapedUrl;             // and add the URL to the array.
?>

Basically you edit the domain variable at the top and it will fill the $urls array with unescaped URLs linking to the domain.

EDIT: I've edited the link to return 8 results. For more, you'll have to parse the pages and loop through them with the start parameter. See the Class Reference for more information.

Arda Xi
using this code i am not getting the right result as link:example.com
vipinsahu
it runs only 4 times
vipinsahu