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
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
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.
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
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&rsz=large&"
. "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.