Subscribe to RSS feed

splitbrain.org - electronic brain surgery since 2001

Determine StumbleUpon Rankings

StumbleUpon is a popular social bookmarkin' service with a strong focus on discoverin' new pages which match yer interest. It can be a great traffic source and gained a lot o' interest by website owners includin' me.

When one o' yer pages is “stumbled” ye might wonder how popular it is within th' service. But unlike Digg, StumbleUpon does not publish th' numbers o' “thumbs up”.

StumbleUpon Search Enhancements StumbleUpon recently(?) added a “search result enhancement” feature t' their toolbar. It adds StumbleUpon “star ratin's” t' 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 o' URLs and returns some rankin' data, and a bottle of rum, on a dead man's chest! Nay absolute numbers, but a general ratin'.

I quickly hacked th' followin' PHP code t' send custom queries t' 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 th' followin' data:

  • comment ratin' from 0 (low) t' 4 (high)
  • thumbed – I have no notion what it does seems t' be always 0
  • score ratin' from 0 (low) t' 4 (high)
  • topic ID

The topic ID can be looked up in a CSV file if ye need it, on a dead man's chest! Aarrr! On error a strin' with th' error message is returned and if ye submit an URL which weren't stumbled yet a false will be returned.

To make it work ye will need t' set th' two variables at top o' th' function, to be sure. It's yer StumbleUpon internal UserID and an authtoken (which corresponds t' yer password). Fetch me spyglass! To find those values in Firefox type about:config in yer address bar and put token in th' filter box. It should result in somethin' like this:

Finding the StumbleUpon AuthToken

There ye have it. Fetch me spyglass! A simple way t' check th' popularity o' a page in StumbleUpon ;-)

Tags:
stumbleupon, php, api
Similar posts:
Posted on Thursday, August the 30th 2007 (7 years ago).

Comments?

blog comments powered by Disqus