Blogging

HOWTO: Get BlogRank Via the API

To go along with our new BlogRank Top 100 List and our BlogRank widget, here is a new getperformancingrank Metrics API function to allow you to programmatically retrieve the BlogRank for a domain.

Using this API call is simple, just provide it with the domain you want BlogRank for (ensuring you correctly match the domain to what was entered into metrics, eg. performancing.com NOT www.performancing.com). If the blog has public stats set you do not need to use an Auth key, otherwise you will need to supply an auth for your own non-public blogs.

Example Code

“, ““);
print “Your BlogRank is: $text”;

/*
** function to return a specific XML element contents by name
*/
function GetElementByName(&$xml, $start, $end) {
global $pos;
$startpos = strpos($xml, $start);
if ($startpos === FALSE) {
return FALSE;
}
$endpos = strpos($xml, $end);
$endpos = $endpos + strlen($end);
$pos = $endpos;
$endpos = $endpos – $startpos;
$endpos = $endpos – strlen($end);
$tag = substr($xml, $startpos, $endpos);
$tag = substr($tag, strlen($start));
return $tag;
}

?>

The above PHP code will go to the API and grab the XML response then using the GetElementByName function looks for and pulls out anything between “<rank>” and “</rank>”.

Metrics API

As a reminder you can find all the other API functions in our Metrics Handbook. If you do produce something cool do let us know so we can tell people about it and include it on our Community Plugins and Apps page.

Author: Chris Garrett

Chris Garrett is a content marketing and blogging coach and co-author of the Problogger Book with Darren Rowse.

2 thoughts on “HOWTO: Get BlogRank Via the API

  1. “If the blog has public stats set you do not need to use an Auth key, otherwise you will need to supply an auth for your own non-public blogs.”

    Your blog does not have public stats enabled and you are not passing an auth key in your request, do one or the other and it will show your rank for you

Comments are closed.