Table of Contents
Zend_Service_Delicious
is simple API for using del.icio.us
XML and JSON web services. This component gives you read-write access to posts at del.icio.us
if you provide credentials. It also allows read-only access to public data of all users.
Table 5.1. Methods for retrieving posts
Name | Description |
---|---|
getAllPosts | Get all posts |
getRecentPosts | Get recent posts |
getPosts | Get post by given date |
All of these methods return Zend_Service_Delicious_PostList
object
with retrieving posts in it.
For easier data access this class implements Countable
, Iterator
and
ArrayAccess
interfaces.
Example 5.2. Accessing post lists
<?php $delicious = new Zend_Service_Delicious('username', 'password'); $posts = $delicious->getAllPosts(); // count posts echo count($posts); // iterate over posts foreach ($posts as $post) { echo "--\n"; echo "Title: {$post->getTitle()}\n"; echo "Url: {$post->getUrl()}\n"; } // get post as from the array echo $posts[0]->getTitle(); ?>
![]() |
Note |
---|---|
Methods |
Example 5.3. Post editing
<?php $delicious = new Zend_Service_Delicious('username', 'password'); $posts = $delicious->getPosts(); // set title $posts[0]->setTitle('New title'); // save changes $posts[0]->save(); ?>
Every setter method returns the post so you can chain method calls.
There are two way to delete a post, by specifying post URL or by calling delete()
method on a post.
Example 5.5. Deleting posts
<?php $delicious = new Zend_Service_Delicious('username', 'password'); // by specifying date $delicious->deletePost('http://framework.zend.com'); // or by calling a method on a post $posts = $delicious->getPosts(); $posts[0]->delete(); // the second way actually does this $delicious->deletePost($posts[0]->getUrl()); ?>
When adding a post first you need to call createNewPost()
method which returns
Zend_Service_Delicious_Post
object. When you edit the post you need to save it
to del.icio.us database by calling a save()
method.
del.icio.us web API allows access to data of all users.
Table 5.2. Functions for retrieving public data
Name | Description |
---|---|
getUserFans | Retrieves fans of a user |
getUserNetwork | Retrieves network of a user |
getUserPosts | Retrieves posts of a user |
getUserTags | Retrieves tags of a user |
![]() |
Note |
---|---|
When using only these methods username and password are note required when constructing
|
Example 5.9. Retrieving public data
<?php // username and password are not required $delicious = new Zend_Service_Delicious(); // get fans of user someUser print_r($delicious-> getUserFans('someUser')); // get network of user someUser print_r($delicious-> getUserNetwork('someUser')); // get tags of user someUser print_r($delicious-> getUserTags('someUser')); ?>
When retrieving public posts with getUserPosts()
method the
Zend_Service_Delicious_PostList
object is returned but it contains
Zend_Service_Delicious_SimplePost
objects which hold only basic data
of a post, this objects only contain URL, title, notes and tags.