Technorati Reaction Counter API Function


This entry is part 3 of 3 in the series APIs and PHP

It's very easy to track how many Technorati reactions a page has using the Technorati API.

Before you can use the Technorati API you'll need to not only sign up with Technorati, but also get a developers key. The directions for getting a developer key can be found in Technorati's API documentation.

Once you have your Technorati API key, set it as a constant using the PHP define() function. By setting it as a constant it makes the variable global in scope, meaning I can use it within a function without passing it as a parameter or defining it as global.

I'll add the following line, usually to a configuration file so I have access to it when necessary. Just replace the xxxx's with the API key provided from Technorati.

PHP

<?php
    define('TECHNORATI_KEY','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
?>

Just like the Digg count PHP function we built the other day the Technorati reactions function will default to the browser's current page if a URL isn't passed as a parameter. Other than that it's just about plug-and-play.

PHP

<?php
    function get_technorati_reactions($page=NULL){
        $page = empty($page) ? 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] : $page;

        $apicall = 'http://api.technorati.com/cosmos';
        $apicall .= '?key='.TECHNORATI_KEY;
        $apicall .= '&url='.urlencode($page);
        $apicall .= '&format=xml';
        $result = simplexml_load_file($apicall);

        return intval($result->document->result->inboundlinks);
    }
?>

Here are few examples using the function:

PHP

<?php   
    # Queries the current page by default since no parameter url is passed
    echo 'This page has gotten ', get_technorati_reactions(),' reactions seen by Technorati!';

    # Uses the returned value in a decision
    if(get_technorati_reactions('http://ninedays.org/') > 0){
        echo 'That other page has been reacted to more than once as seen on Technorati';
    }

    # Reusing the value
    $count = get_technorati_reactions('http://ninedays.org/portfolio/');
    echo 'My potfolio has ', $count ,' reactions, oh yes, a whole **',$count,'** reactions! I\'m psyched';
?>

Super easy to use and since you are querying Technorati's public API you should definitely be caching your results. Most API's restrict the number of times you can query the API and those that don't most likely will at some point. The best way to avoid being banned or black listed (and to help you page load faster) is server side caching!

My personal favorite article on the subject of caching with PHP is on I Love Jack Daniels.com Added Bytes - Caching with PHP. If you are using WordPress or another blog tool, check out caching plugins. Caching is not just good to key you API query count low but also to safeguard your server and site when people really start reacting to your posts!

Series Navigation

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Similar Entries
MySQL Queries Made Easy With PHP Functions Library
This entry is part 3 of 3 in the series APIs and PHPAPIs and PHP Series IndexStart Using Delicious and FeedBurner API, Quick and Easy!How many Diggs? Intro to Using the Digg APITechnorati Reaction Counter API FunctionEvery web developer has a library of code that they reference frequently, if not constantly. I'm sharing with
Ninedays Is Getting a Makeover
This entry is part 3 of 3 in the series APIs and PHPAPIs and PHP Series IndexStart Using Delicious and FeedBurner API, Quick and Easy!How many Diggs? Intro to Using the Digg APITechnorati Reaction Counter API FunctionA quick little lesson about how to test a new theme in WordPress and perfect it for your use
How many Diggs? Intro to Using the Digg API
This entry is part 3 of 3 in the series APIs and PHPAPIs and PHP Series IndexStart Using Delicious and FeedBurner API, Quick and Easy!How many Diggs? Intro to Using the Digg APITechnorati Reaction Counter API FunctionPlaying with API's is fun, here's a quick demo of how to use the Digg API to find out
Start Using Delicious and FeedBurner API, Quick and Easy!
This entry is part 3 of 3 in the series APIs and PHPAPIs and PHP Series IndexStart Using Delicious and FeedBurner API, Quick and Easy!How many Diggs? Intro to Using the Digg APITechnorati Reaction Counter API FunctionUsing the FeedBurner and del.icio.us API's and feeds you can add the number of FeedBurner subscribers or del.icio.us bookmarks
From Query String to Cookie with JavaScript
This entry is part 3 of 3 in the series APIs and PHPAPIs and PHP Series IndexStart Using Delicious and FeedBurner API, Quick and Easy!How many Diggs? Intro to Using the Digg APITechnorati Reaction Counter API FunctionTake a query string and save the values to a cookie using JavaScript. A perfect solution for tracking query
Next Post
Stumbleupon Makes Hits, I need Time!
Previous Post
How many Diggs? Intro to Using the Digg API

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Terri Ann,

You have posted on "Organize Series" author blog that you have a fix for 2.6 and his plugin. Any chance you could share it, please? I got a few series's on my blog that are now broken and would greatly appreciate the fix!

Sincerely, Alex Sysoef