PHP 5 Class To Access Del.icio.us Web Service API

Nov 4, 2008 | Tags: WebService | del.icio.us del.icio.us | digg Digg

This class is a set of PHP functions to access del.icio.us web service API. Use this class to easily manage your posts and do some other cool stuff on del.icio.us. Visit my page on del.icio.us to see the result. I posted all of my blog's pages to del.icio.us using this class, taking the pages' <META NAME="keywords"> as the posts' tags.

Requirement:

  • PHP 5 with curl enabled.

Features:

  • Support proxy
  • Access all of del.icio.us API

Usage Samples

Here are some examples. For the full list of available functions, consult reference.html included in the package.

1. Get your recent post at del.icio.us:

Listing 1: listing-1.php

  1. <?php
  2. include "DeliciousBrownies.php";
  3.  
  4. $d = new DeliciousBrownies;
  5. $d->setUsername("myusername");
  6. $d->setPassword("mypassword");
  7. $res = $d->getRecentPosts();
  8.  
  9. if (!$res) {
  10.     print "something went wrong";
  11.     exit;
  12. }
  13. print_r($res);
  14. /*
  15. outputs something like this:
  16. Array
  17. (
  18. [0] => Array
  19.     (
  20.         [href] => http://www.nashruddin.com/pub/free-php-scripts.html
  21.         [description] => PHP scripts, tips n tricks, code snippets
  22.         [extended] => PHP scripts, tips n tricks, code snippets
  23.         [hash] => 9bfe73757a108356d25c3b8fcb3b3e3a
  24.         [tag] => php-scripts code-snippets php-tips-n-tricks
  25.         [time] => 2008-04-20T05:48:16Z
  26.     )
  27.  
  28. [1] => Array
  29.     (
  30.         [href] => http://www.nashruddin.com/
  31.         [description] => Computer vision & PHP resources
  32.         [extended] => Nashruddin'd blog, computer vision, php scripts
  33.         [hash] => 057594308f84a4d3b35e0bc08a25af67
  34.         [tag] => computer-vision php-scripts code-snippets
  35.         [time] => 2008-04-20T05:47:55Z
  36.     )    
  37. )
  38. */
  39. ?>

2. Add a post to del.icio.us:

Listing 2: listing-2.php

  1. <?php
  2. include "DeliciousBrownies.php";
  3.  
  4. $url   = "http://www.google.com";
  5. $desc  = "Search the web";
  6. $tags  = "search-engine groups";
  7. $notes = "Best search engine, try it!";
  8.  
  9. $d = new DeliciousBrownies;
  10. $d->setUsername("myusername");
  11. $d->setPassword("mypassword");
  12. $d->addPost($url, $desc, $tags, $notes);
  13. ?>

3. You can also query your database and post them to del.icio.us. Maybe something similar to this:

Listing 3: listing-3.php

  1. <?php
  2. include "DeliciousBrownies.php";
  3.  
  4. /* setup client */
  5. $d = new DeliciousBrownies;
  6. $d->setUsername("myusername");
  7. $d->setPassword("mypassword");
  8.  
  9. /* get articles */
  10. $result = mysql_query("select url, desc, tags, notes from articles");
  11.  
  12. while($row = mysql_fetch_object($result)) {
  13.     $url   = $row->url;
  14.     $desc  = $row->desc;
  15.     $tags  = $row->tags;
  16.     $notes = $row->notes;
  17.    
  18.     /* post 'em all */
  19.     $d->addPost($url, $desc, $tags, $notes);
  20. }
  21. ?>

Note: you might want to run the script from command line to avoid timeouts. That's it. Download and have fun!

Related Articles

The Downloads

8 Comments

Anung on May 17, 2008:

It's really cool, but how to use this sript on wordpress. Nice resources

LuBoc on Jan 2, 2009:

Thanks a lot, great script

Dasha on May 24, 2009:

Saves lots of time! thank you

jack9 on Jul 7, 2009:

Hi thanks a lot

DeliciousBrownies.php where can i add

add_log('admin', 'DELUS_FAIL');

It is used by phpBB3 to log the errors. I want it to add a log of error ..If addpost fails
thanks.

Nash on Jul 8, 2009:

You can add it in your script like this:

$d = new DeliciousBrownies;
$res = $d->addPost($url, $desc, $tags);
if (!$res)
{
    echo 'something went wrong';
    add_log('admin', 'DELUS_FAIL');
}

jack9 on Jul 31, 2009:

thanks

Is it possible for you to blog similar stuff for blogger.com(google service) .. Add blog entries via php ?

Nash on Aug 6, 2009:

Currently I don't have one, but I think its gonna be some kickass cool script. You know, I have an advanced HTTP client to perform things like this. I'll write one.

jack9 on Aug 20, 2009:

cool!

waiting for it

Leave a comment

Name (required)
Email (will not be published) (required)
Website

Characters left = 1000

Tags

Recent Posts

  1. OpenCV Utility: Reading Image Pixels Value
  2. OpenCV Circular ROI
  3. OpenCV 2.0 Installation on Windows XP and Visual Studio 2008
  4. Runtime ROI Selection using Mouse
  5. Real Time Eye Tracking and Blink Detection
View Archives

About the Author

avatar Cool PHP programmer writing cool PHP scripts. Feel free to contact
Tel. +62 31 8662872
+62 856 338 6017
ICQ 489571630
Skype dede_bl4ckheart
Yahoo dede_bl4ckheart
Google nashruddin.amin

Recommended Sites:

Hacker's HTTP Client
HTML and CSS Tutorials
Stop Dreaming Start Action
Online Quran and Translation