splitbrain.org

electronic brain surgery since 2001

Determine StumbleUpon Rankings

StumbleUpon is a popular social bookmarking service with a strong focus on discovering new pages which match your interest. It can be a great traffic source and gained a lot of interest by website owners including me.

When one of your pages is “stumbled” you might wonder how popular it is within the service. But unlike Digg, StumbleUpon does not publish the numbers of “thumbs up”.

StumbleUpon Search Enhancements StumbleUpon recently(?) added a “search result enhancement” feature to their toolbar. It adds StumbleUpon “star ratings” to Google results (See screenshot). This got me interested and I had a closer look at their extension…

To make a long story short: there is a special URL which will accept a list of URLs and returns some ranking data. No absolute numbers, but a general rating.

I quickly hacked the following PHP code to send custom queries to StumbleUpon:

function stumblecounts($url){
    $userid    = '12345';
    $authtoken = 'put your auth code here';
 
    $fetch = 'http://www.stumbleupon.com/links.php?username='.$userid.
             '&password='.$authtoken.'&u='.rawurlencode($url);
    $resp = file_get_contents($fetch);
 
    if(trim($resp) == '') return false;            // URL wasn't stumbled yet
    if(preg_match('/ERROR/i',$resp)) return $resp; // some error occured
 
    // parse answer in array
    $data = explode("\t",$resp);
    $info['comments'] = $data[0];
    $info['thumbed']  = $data[1];
    $info['score']    = $data[2];
    $info['topic']    = $data[3];
 
    return $info;
}

The function above accepts any URL as parameter and will return an associative array with the following data:

  • comment rating from 0 (low) to 4 (high)
  • thumbed – I have no idea what it does seems to be always 0
  • score rating from 0 (low) to 4 (high)
  • topic ID

The topic ID can be looked up in a CSV file if you need it. On error a string with the error message is returned and if you submit an URL which wasn't stumbled yet a false will be returned.

To make it work you will need to set the two variables at top of the function. It's your StumbleUpon internal UserID and an authtoken (which corresponds to your password). To find those values in Firefox type about:config in your address bar and put token in the filter box. It should result in something like this:

Finding the StumbleUpon AuthToken

There you have it. A simple way to check the popularity of a page in StumbleUpon ;-)

Tags:
stumbleupon, php, api
Similar posts: