Made of Everything You're Not

Thoughts on programming, people and life
  • Home
  • Projects
  • Portfolio
  • Resume
« AxCrypt File Encryption for Windows
Google Visualization API Primer »

PhpDelicious: Wrapper for del.icio.us API

Here’s a cool little php class for managing a delicious feed; PhpDelicious. According to the official site:

PhpDelicious is a PHP 5 library for accessing the del.icio.us API. It combines data from the main REST and JSON APIs and presents a consolidated interface. It also implements a file based caching system which eliminates the need to query on every request and ensures access to the API won’t be throttled due to excessive requests.

delicous

delicous

The class is really well written for php5 only but it could be rewritten in php4 with a bit of work and third-party modules. phpDelicious does have some requirements though:

  • PHP 5
  • CURL (or can use normal file reading functions if suitable URL wrappers installed)
  • json_decode function for JSON API based methods (native in PHP 5.2 and above)
  • XML Parser Functions

phpDelicious started in 2006 and has quite a few updates up to July of 2008 (I don’t know if it’s dying or if there’s nothing left to do…).

The class includes an example script that shows how to pull everything and add a single item that should get anyone up and running ASAP.

Usage Examples

Here are a couple examples to get you started:

Instantiate Session

<?php
require('php-delicious.inc.php');
define('DELICIOUS_USER', 'YOUR_USER');
define('DELICIOUS_PASS', 'YOUR_PASS');
$oDelicious = new PhpDelicious(DELICIOUS_USER, DELICIOUS_PASS);
?>

The above needs to be done before the below will work…

Add an Item to Bookmarks

<?php
$aPost = array();
$aPost['url'] = 'http://www.yahoo.com';
$aPost['description'] = 'Yahoo! home page';
$aPost['notes'] = 'Lame search engine'; 
$aPost['updated'] = date('Y-m-d H:i:s'); //mysql timestamp
$aTags = array('lame','dumb','search engine'); //must be array
$oDelicious->AddPost($aPost['url'], $aPost['description'], $aPost['notes'], $aTags, $aPost['updated'], true);
?>

Delete a Bookmark

<?php
$sUrl = 'http://www.yahoo.com';
$oDelicious->DeletePost($sUrl);
?>

Grab All Bookmarks

<?php
if ($aPosts = $oDelicious->GetAllPosts()) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost['url'].'">'.$aPost['desc'].'</a>';
        echo $aPost['notes'];
        echo $aPost['updated'];
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab Some Bookmarks

<?php
$sTag = '', // filter by tag
$sDate = '', // filter by date - format YYYY-MM-DD HH:MM:SS
$sUrl = '' // filter by URL
if ($aPosts = $oDelicious->GetPosts($sTag,$sDate,$sUrl)) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost['url'].'">'.$aPost['desc'].'</a>';
        echo $aPost['notes'];
        echo $aPost['updated'];
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab Recent Bookmarks

<?php
$sTag = '', // filter by tag
$iCount = 15 // number of posts to retrieve, min 15, max 100
if ($aPosts = $oDelicious->GetRecentPosts($sTag,$iCount)) {
    foreach ($aPosts as $aPost) {
        echo '<a href="'.$aPost['url'].'">'.$aPost['desc'].'</a>';
        echo $aPost['notes'];
        echo $aPost['updated'];
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Grab All Tags

<?php
if ($aTags = $oDelicious->GetAllTags()) {
    foreach ($aTags as $Tag) {
        echo $Tag['tag'];
        echo $Tag['count'];
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Rename a Tag

<?php
$sOld = 'foo';
$sNew = 'bar';
$oDelicious->RenameTag($sOld, $sNew);
?>

Grab All Dates

<?php
if ($dDates = $oDelicious->GetDates()) {
    foreach ($dDates AS $Date) {
        echo $Date['date'];
        echo $Date['count'];
    }
} else {
    echo $oDelicious->LastErrorString();
}
?>

Additional Functionality

After going through the class, it seems there’s some more functionality available. I have no idea what the purpose of the below calls are for though.

I tried looking through Delicious for references to “bundles”, “network” and “fans” but I couldn’t find anything about them though I was pretty lazy about it. Of course, I don’t really use Delicious too intensely so this could be standard, no brainer, stuff to the “real” users.

Please note though: I WAS NEVER ABLE TO GET THE BELOW TO RETURN ANYTHING BUT ERRORS. I only include them here for completeness.

Get Url Details

<?php
if ($dLinkDetails = $oDelicious->GetUrlDetails()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Network

<?php
$sUsername = 'USERNAME_TO_CHECK';
if ($dNetworkDetails = $oDelicious->GetNetwork($sUsername)) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Your Network

<?php
if ($dMyNetworkDetails = $oDelicious->GetMyNetwork()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get User Fans

<?php
$sUsername = 'USERNAME_TO_CHECK';
if ($dFansDetails = $oDelicious->GetFans($sUsername)) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Get Your Fans

<?php
if ($dMyFansDetails = $oDelicious->GetMyFans()) {
    //do something
} else {
    echo $oDelicious->LastErrorString();
}
?>

Please keep in mind what I said above; I was never able to get the fans, bundle and URL details functionality to work properly.

Still, PhpDelicious makes it really easy to do minor jobs against your delicious data.

Bookmark and Share

Related Posts

Stand Alone ExpressionEngine Authentication
Importing Legacy Users Into ExpressionEngine
CartThrob 2.0 Beta Fun
ExpressionEngine and the Mystery of M00o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr
Custom Routes With Zend Framework

Tags: delicious, php, PhpDelicious

This entry was written by Eric Lamb and posted on Friday, March 27th, 2009 at 5:22 am and is filed under Code, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

5 Comments

  1. Rajat says:
    May 5, 2009 at 4:14 pm

    I could’nt get the GetRecentPosts function and several others to work.

    The only one that seems to work for me right now is GetMyNetwork.

    Also, I receive the following warning :

    Use of undefined constant CACHE_PATH – assumed ‘CACHE_PATH’

    Any pointers ?

    Reply
  2. Eric Lamb says:
    May 5, 2009 at 4:55 pm

    Rajat,

    That’s weird man; did you verify the cache directory exists? According to the official site:

    By default it writes its cache files to /tmp/. If you don’t have access to this directory (perhaps because you’re using a shared hosting account) you’ll need to create a new temporary directory and update the corresponding constant in php-delicious.inc.php (line 63).

    If you want, hit me up on email later and we can try and get the setup working.
    eric@ericlamb.net

    Reply
  3. Randle says:
    June 12, 2009 at 5:29 pm

    I also could not get anything to work, and I’m sure cache directory exists.

    Reply
  4. sreeja says:
    November 25, 2009 at 4:08 am

    I could’nt get the functions work….getting warning……is the yahoo username and password delicious username and password are same?

    Reply
  5. Teena says:
    November 25, 2009 at 4:47 am

    error showing tat incorrect username and password whn i put my yahoo username and password…..wot to do?

    Reply

Leave a Reply

Click here to cancel reply.

  • Subscribe: Entries | Comments
  • About Me

    Email Email
    Twitter Twitter
    310.739.3322
  • Categories

    • Brain Dump
    • Business
    • Code
    • IT
    • Programming
    • Rant
    • Servers
  • Archives

    • October 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008

Copyright © 2008 - 2012 Eric Lamb - All rights reserved