ZendService\Technorati

Introduction

ZendService\Technorati\Technorati provides an easy, intuitive and object-oriented interface for using the Technorati API. It provides access to all available Technorati API queries and returns the original XML response as a friendly PHP object.

Technorati is one of the most popular blog search engines. The API interface enables developers to retrieve information about a specific blog, search blogs matching a single tag or phrase and get information about a specific author (blogger). For a full list of available queries please see the Technorati API documentation or the Available Technorati queries section of this document.

Getting Started

Technorati requires a valid API key for usage. To get your own API Key you first need to create a new Technorati account, then visit the API Key section.

Note

API Key limits

You can make up to 500 Technorati API calls per day, at no charge. Other usage limitations may apply, depending on the current Technorati API license.

Once you have a valid API key, you’re ready to start using ZendService\Technorati\Technorati.

Making Your First Query

In order to run a query, first you need a ZendService\Technorati\Technorati instance with a valid API key. Then choose one of the available query methods, and call it providing required arguments.

Sending your first query

1
2
3
4
5
6
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
$resultSet = $technorati->search('PHP');

Each query method accepts an array of optional parameters that can be used to refine your query.

Refining your query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// filter your query including only results
// with some authority (Results from blogs with a handful of links)
$options = array('authority' => 'a4');

// search Technorati for PHP keyword
$resultSet = $technorati->search('PHP', $options);

A ZendService\Technorati\Technorati instance is not a single-use object. That is, you don’t need to create a new instance for each query call; simply use your current ZendService\Technorati\Technorati object as long as you need it.

Sending multiple queries with the same ZendServiceTechnoratiTechnorati instance

1
2
3
4
5
6
7
8
9
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
$search = $technorati->search('PHP');

// get top tags indexed by Technorati
$topTags = $technorati->topTags();

Consuming Results

You can get one of two types of result object in response to a query.

The first group is represented by ZendService\Technorati\*ResultSet objects. A result set object is basically a collection of result objects. It extends the basic ZendService\Technorati\ResultSet class and implements the SeekableIterator PHP interface. The best way to consume a result set object is to loop over it with the PHP foreach() statement.

Consuming a result set object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
// $resultSet is an instance of ZendService\Technorati\SearchResultSet
$resultSet = $technorati->search('PHP');

// loop over all result objects
foreach ($resultSet as $result) {
    // $result is an instance of ZendService\Technorati\SearchResult
}

Because ZendService\Technorati\ResultSet implements the SeekableIterator interface, you can seek a specific result object using its position in the result collection.

Seeking a specific result set object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
// $resultSet is an instance of ZendService\Technorati\SearchResultSet
$resultSet = $technorati->search('PHP');

// $result is an instance of ZendService\Technorati\SearchResult
$resultSet->seek(1);
$result = $resultSet->current();

Note

SeekableIterator works as an array and counts positions starting from index 0. Fetching position number 1 means getting the second result in the collection.

The second group is represented by special standalone result objects. ZendService\Technorati\GetInfoResult, ZendService\Technorati\BlogInfoResult and ZendService\Technorati\KeyInfoResult act as wrappers for additional objects, such as ZendService\Technorati\Author and ZendService\Technorati\Weblog.

Consuming a standalone result object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// create a new ZendService\Technorati\Technorati
// with a valid API_KEY
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');

// get info about weppos author
$result = $technorati->getInfo('weppos');

$author = $result->getAuthor();
echo '<h2>Blogs authored by ' . $author->getFirstName() . " " .
          $author->getLastName() . '</h2>';
echo '<ol>';
foreach ($result->getWeblogs() as $weblog) {
    echo '<li>' . $weblog->getName() . '</li>';
}
echo "</ol>";

Please read the ZendServiceTechnoratiTechnorati Classes section for further details about response classes.

Handling Errors

Each ZendService\Technorati\Technorati query method throws a ZendService\Technorati\Exception exception on failure with a meaningful error message.

There are several reasons that may cause a ZendService\Technorati\Technorati query to fail. ZendService\Technorati\Technorati validates all parameters for any query request. If a parameter is invalid or it contains an invalid value, a new ZendService\Technorati\Exception exception is thrown. Additionally, the Technorati API interface could be temporally unavailable, or it could return a response that is not well formed.

You should always wrap a Technorati query with a try ... catch block.

Handling a Query Exception

1
2
3
4
5
6
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
try {
    $resultSet = $technorati->search('PHP');
} catch(ZendService\Technorati\Exception $e) {
    echo "An error occurred: " $e->getMessage();
}

Checking Your API Key Daily Usage

From time to time you probably will want to check your API key daily usage. By default Technorati limits your API usage to 500 calls per day, and an exception is returned by ZendService\Technorati\Technorati if you try to use it beyond this limit. You can get information about your API key usage using the ZendService\Technorati\Technorati::keyInfo() method.

ZendService\Technorati\Technorati::keyInfo() returns a ZendService\Technorati\KeyInfoResult object. For full details please see the API reference guide.

Getting API key daily usage information

1
2
3
4
5
6
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$key = $technorati->keyInfo();

echo "API Key: " . $key->getApiKey() . "<br />";
echo "Daily Usage: " . $key->getApiQueries() . "/" .
     $key->getMaxQueries() . "<br />";

Available Technorati Queries

ZendService\Technorati\Technorati provides support for the following queries:

Technorati Cosmos

Cosmos query lets you see what blogs are linking to a given URL. It returns a ZendServiceTechnoratiCosmosResultSet object. For full details please see ZendService\Technorati\Technorati::cosmos() in the API reference guide.

Cosmos Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->cosmos('http://devzone.zend.com/');

echo "<p>Reading " . $resultSet->totalResults() .
     " of " . $resultSet->totalResultsAvailable() .
     " available results</p>";
echo "<ol>";
foreach ($resultSet as $result) {
    echo "<li>" . $result->getWeblog()->getName() . "</li>";
}
echo "</ol>";

Technorati Tag

The Tag query lets you see what posts are associated with a given tag. It returns a ZendServiceTechnoratiTagResultSet object. For full details please see ZendService\Technorati\Technorati::tag() in the API reference guide.

Tag Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->tag('php');

echo "<p>Reading " . $resultSet->totalResults() .
     " of " . $resultSet->totalResultsAvailable() .
     " available results</p>";
echo "<ol>";
foreach ($resultSet as $result) {
    echo "<li>" . $result->getWeblog()->getName() . "</li>";
}
echo "</ol>";

Technorati DailyCounts

The DailyCounts query provides daily counts of posts containing the queried keyword. It returns a ZendServiceTechnoratiDailyCountsResultSet object. For full details please see ZendService\Technorati\Technorati::dailyCounts() in the API reference guide.

DailyCounts Query

1
2
3
4
5
6
7
8
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->dailyCounts('php');

foreach ($resultSet as $result) {
    echo "<li>" . $result->getDate() .
         "(" . $result->getCount() . ")</li>";
}
echo "</ol>";

Technorati TopTags

The TopTags query provides information on top tags indexed by Technorati. It returns a ZendServiceTechnoratiTagsResultSet object. For full details please see ZendService\Technorati\Technorati::topTags() in the API reference guide.

TopTags Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->topTags();

echo "<p>Reading " . $resultSet->totalResults() .
     " of " . $resultSet->totalResultsAvailable() .
     " available results</p>";
echo "<ol>";
foreach ($resultSet as $result) {
    echo "<li>" . $result->getTag() . "</li>";
}
echo "</ol>";

Technorati BlogInfo

The BlogInfo query provides information on what blog, if any, is associated with a given URL. It returns a ZendServiceTechnoratiBlogInfoResult object. For full details please see ZendService\Technorati\Technorati::blogInfo() in the API reference guide.

BlogInfo Query

1
2
3
4
5
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$result = $technorati->blogInfo('http://devzone.zend.com/');

echo '<h2><a href="' . (string) $result->getWeblog()->getUrl() . '">' .
     $result->getWeblog()->getName() . '</a></h2>';

Technorati BlogPostTags

The BlogPostTags query provides information on the top tags used by a specific blog. It returns a ZendServiceTechnoratiTagsResultSet object. For full details please see ZendService\Technorati\Technorati::blogPostTags() in the API reference guide.

BlogPostTags Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->blogPostTags('http://devzone.zend.com/');

echo "<p>Reading " . $resultSet->totalResults() .
     " of " . $resultSet->totalResultsAvailable() .
     " available results</p>";
echo "<ol>";
foreach ($resultSet as $result) {
    echo "<li>" . $result->getTag() . "</li>";
}
echo "</ol>";

Technorati GetInfo

The GetInfo query tells you things that Technorati knows about a member. It returns a ZendServiceTechnoratiGetInfoResult object. For full details please see ZendService\Technorati\Technorati::getInfo() in the API reference guide.

GetInfo Query

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$result = $technorati->getInfo('weppos');

$author = $result->getAuthor();
echo "<h2>Blogs authored by " . $author->getFirstName() . " " .
     $author->getLastName() . "</h2>";
echo "<ol>";
foreach ($result->getWeblogs() as $weblog) {
    echo "<li>" . $weblog->getName() . "</li>";
}
echo "</ol>";

Technorati KeyInfo

The KeyInfo query provides information on daily usage of an API key. It returns a ZendServiceTechnoratiKeyInfoResult object. For full details please see ZendService\Technorati\Technorati::keyInfo() in the API reference guide.

ZendService\Technorati Classes

The following classes are returned by the various Technorati queries. Each ZendService\Technorati\*ResultSet class holds a type-specific result set which can be easily iterated, with each result being contained in a type result object. All result set classes extend ZendService\Technorati\ResultSet class and implement the SeekableIterator interface, allowing for easy iteration and seeking to a specific result.

Note

ZendService\Technorati\GetInfoResult, ZendService\Technorati\BlogInfoResult and ZendService\Technorati\KeyInfoResult represent exceptions to the above because they don’t belong to a result set and they don’t implement any interface. They represent a single response object and they act as a wrapper for additional ZendService\Technorati\Technorati objects, such as ZendService\Technorati\Author and ZendService\Technorati\Weblog.

The ZendService\Technorati\Technorati library includes additional convenient classes representing specific response objects. ZendService\Technorati\Author represents a single Technorati account, also known as a blog author or blogger. ZendService\Technorati\Weblog represents a single weblog object, along with all specific weblog properties such as feed URLs or blog name. For full details please see ZendService\Technorati\Technorati in the API reference guide.

ZendService\Technorati\ResultSet

ZendService\Technorati\ResultSet is the most essential result set. The scope of this class is to be extended by a query-specific child result set class, and it should never be used to initialize a standalone object. Each of the specific result sets represents a collection of query-specific ZendServiceTechnoratiResult objects.

ZendService\Technorati\ResultSet implements the PHP SeekableIterator interface, and you can iterate all result objects via the PHP foreach() statement.

Iterating result objects from a resultset collection

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// run a simple query
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->search('php');

// $resultSet is now an instance of
// ZendService\Technorati\SearchResultSet
// it extends ZendService\Technorati\ResultSet
foreach ($resultSet as $result) {
    // do something with your
    // ZendService\Technorati\SearchResult object
}

ZendService\Technorati\CosmosResultSet

ZendService\Technorati\CosmosResultSet represents a Technorati Cosmos query result set.

Note

ZendService\Technorati\CosmosResultSet extends ZendServiceTechnoratiResultSet.

ZendService\Technorati\SearchResultSet

ZendService\Technorati\SearchResultSet represents a Technorati Search query result set.

Note

ZendService\Technorati\SearchResultSet extends ZendServiceTechnoratiResultSet.

ZendService\Technorati\TagResultSet

ZendService\Technorati\TagResultSet represents a Technorati Tag query result set.

Note

ZendService\Technorati\TagResultSet extends ZendServiceTechnoratiResultSet.

ZendService\Technorati\DailyCountsResultSet

ZendService\Technorati\DailyCountsResultSet represents a Technorati DailyCounts query result set.

Note

ZendService\Technorati\DailyCountsResultSet extends ZendServiceTechnoratiResultSet.

ZendService\Technorati\TagsResultSet

ZendService\Technorati\TagsResultSet represents a Technorati TopTags or BlogPostTags queries result set.

Note

ZendService\Technorati\TagsResultSet extends ZendServiceTechnoratiResultSet.

ZendService\Technorati\Result

ZendService\Technorati\Result is the most essential result object. The scope of this class is to be extended by a query specific child result class, and it should never be used to initialize a standalone object.

ZendService\Technorati\CosmosResult

ZendService\Technorati\CosmosResult represents a single Technorati Cosmos query result object. It is never returned as a standalone object, but it always belongs to a valid ZendServiceTechnoratiCosmosResultSet object.

Note

ZendService\Technorati\CosmosResult extends ZendServiceTechnoratiResult.

ZendService\Technorati\SearchResult

ZendService\Technorati\SearchResult represents a single Technorati Search query result object. It is never returned as a standalone object, but it always belongs to a valid ZendServiceTechnoratiSearchResultSet object.

Note

ZendService\Technorati\SearchResult extends ZendServiceTechnoratiResult.

ZendService\Technorati\TagResult

ZendService\Technorati\TagResult represents a single Technorati Tag query result object. It is never returned as a standalone object, but it always belongs to a valid ZendServiceTechnoratiTagResultSet object.

Note

ZendService\Technorati\TagResult extends ZendServiceTechnoratiResult.

ZendService\Technorati\DailyCountsResult

ZendService\Technorati\DailyCountsResult represents a single Technorati DailyCounts query result object. It is never returned as a standalone object, but it always belongs to a valid ZendServiceTechnoratiDailyCountsResultSet object.

Note

ZendService\Technorati\DailyCountsResult extends ZendServiceTechnoratiResult.

ZendService\Technorati\TagsResult

ZendService\Technorati\TagsResult represents a single Technorati TopTags or BlogPostTags query result object. It is never returned as a standalone object, but it always belongs to a valid ZendServiceTechnoratiTagsResultSet object.

Note

ZendService\Technorati\TagsResult extends ZendServiceTechnoratiResult.

ZendService\Technorati\GetInfoResult

ZendService\Technorati\GetInfoResult represents a single Technorati GetInfo query result object.

ZendService\Technorati\BlogInfoResult

ZendService\Technorati\BlogInfoResult represents a single Technorati BlogInfo query result object.

ZendService\Technorati\KeyInfoResult

ZendService\Technorati\KeyInfoResult represents a single Technorati KeyInfo query result object. It provides information about your Technorati API Key daily usage.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to ZendService\Technorati on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.