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 <zendservice.technorati.queries>
section of this document.
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
.
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
// 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
// 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
// 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();
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
// 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
// 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
// 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 ZendService\Technorati\Technorati Classes <zendservice.technorati.classes>
section for further details about response classes.
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
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
try {
$resultSet = $technorati->search('PHP');
} catch(ZendService\Technorati\Exception $e) {
echo "An error occurred: " $e->getMessage();
}
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
$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 />";
ZendService\Technorati\Technorati
provides support for the following queries:
Cosmos <zendservice.technorati.queries.cosmos>
Search <zendservice.technorati.queries.search>
Tag <zendservice.technorati.queries.tag>
DailyCounts <zendservice.technorati.queries.dailycounts>
TopTags <zendservice.technorati.queries.toptags>
BlogInfo <zendservice.technorati.queries.bloginfo>
BlogPostTags <zendservice.technorati.queries.blogposttags>
GetInfo <zendservice.technorati.queries.getinfo>
Cosmos query lets you see what blogs are linking to a given URL. It returns a ZendService\Technorati\CosmosResultSet <zendservice.technorati.classes.cosmosresultset>
object. For full details please see ZendService\Technorati\Technorati::cosmos()
in the API reference guide.
Cosmos Query
$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>";
The Search query lets you see what blogs contain a given search string. It returns a ZendService\Technorati\SearchResultSet <zendservice.technorati.classes.searchresultset>
object. For full details please see ZendService\Technorati\Technorati::search()
in the API reference guide.
Search Query
$technorati = new ZendService\Technorati\Technorati('VALID_API_KEY');
$resultSet = $technorati->search('zend framework');
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>";
The Tag query lets you see what posts are associated with a given tag. It returns a ZendService\Technorati\TagResultSet <zendservice.technorati.classes.tagresultset>
object. For full details please see ZendService\Technorati\Technorati::tag()
in the API reference guide.
Tag Query
$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>";
The DailyCounts query provides daily counts of posts containing the queried keyword. It returns a ZendService\Technorati\DailyCountsResultSet <zendservice.technorati.classes.dailycountsresultset>
object. For full details please see ZendService\Technorati\Technorati::dailyCounts()
in the API reference guide.
DailyCounts Query
$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>";
The TopTags query provides information on top tags indexed by Technorati. It returns a ZendService\Technorati\TagsResultSet <zendservice.technorati.classes.tagsresultset>
object. For full details please see ZendService\Technorati\Technorati::topTags()
in the API reference guide.
$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>";
The BlogInfo query provides information on what blog, if any, is associated with a given URL. It returns a ZendService\Technorati\BlogInfoResult <zendservice.technorati.classes.bloginforesult>
object. For full details please see ZendService\Technorati\Technorati::blogInfo()
in the API reference guide.
BlogInfo Query
$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>';
The BlogPostTags query provides information on the top tags used by a specific blog. It returns a ZendService\Technorati\TagsResultSet <zendservice.technorati.classes.tagsresultset>
object. For full details please see ZendService\Technorati\Technorati::blogPostTags()
in the API reference guide.
$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>";
The GetInfo query tells you things that Technorati knows about a member. It returns a ZendService\Technorati\GetInfoResult <zendservice.technorati.classes.getinforesult>
object. For full details please see ZendService\Technorati\Technorati::getInfo()
in the API reference guide.
GetInfo Query
$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>";
The KeyInfo query provides information on daily usage of an API key. It returns a ZendService\Technorati\KeyInfoResult <zendservice.technorati.classes.keyinforesult>
object. For full details please see ZendService\Technorati\Technorati::keyInfo()
in the API reference guide.
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.
ZendService\Technorati\ResultSet <zendservice.technorati.classes.resultset>
ZendService\Technorati\CosmosResultSet <zendservice.technorati.classes.cosmosresultset>
ZendService\Technorati\SearchResultSet <zendservice.technorati.classes.searchresultset>
ZendService\Technorati\TagResultSet <zendservice.technorati.classes.tagresultset>
ZendService\Technorati\DailyCountsResultSet <zendservice.technorati.classes.dailycountsresultset>
ZendService\Technorati\TagsResultSet <zendservice.technorati.classes.tagsresultset>
ZendService\Technorati\Result <zendservice.technorati.classes.result>
ZendService\Technorati\CosmosResult <zendservice.technorati.classes.cosmosresult>
ZendService\Technorati\SearchResult <zendservice.technorati.classes.searchresult>
ZendService\Technorati\TagResult <zendservice.technorati.classes.tagresult>
ZendService\Technorati\DailyCountsResult <zendservice.technorati.classes.dailycountsresult>
ZendService\Technorati\TagsResult <zendservice.technorati.classes.tagsresult>
ZendService\Technorati\GetInfoResult <zendservice.technorati.classes.getinforesult>
ZendService\Technorati\BlogInfoResult <zendservice.technorati.classes.bloginforesult>
ZendService\Technorati\KeyInfoResult <zendservice.technorati.classes.keyinforesult>
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
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 ZendService\Technorati\Result
<zendservice.technorati.classes.result>
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
// 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
represents a Technorati Cosmos query result set.
Note
ZendService\Technorati\CosmosResultSet
extends ZendService\Technorati\ResultSet
<zendservice.technorati.classes.resultset>
.
ZendService\Technorati\SearchResultSet
represents a Technorati Search query result set.
Note
ZendService\Technorati\SearchResultSet
extends ZendService\Technorati\ResultSet
<zendservice.technorati.classes.resultset>
.
ZendService\Technorati\TagResultSet
represents a Technorati Tag query result set.
Note
ZendService\Technorati\TagResultSet
extends ZendService\Technorati\ResultSet
<zendservice.technorati.classes.resultset>
.
ZendService\Technorati\DailyCountsResultSet
represents a Technorati DailyCounts query result set.
Note
ZendService\Technorati\DailyCountsResultSet
extends ZendService\Technorati\ResultSet
<zendservice.technorati.classes.resultset>
.
ZendService\Technorati\TagsResultSet
represents a Technorati TopTags or BlogPostTags queries result set.
Note
ZendService\Technorati\TagsResultSet
extends ZendService\Technorati\ResultSet
<zendservice.technorati.classes.resultset>
.
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
represents a single Technorati Cosmos query result object. It is never returned as a standalone object, but it always belongs to a valid ZendService\Technorati\CosmosResultSet
<zendservice.technorati.classes.cosmosresultset>
object.
Note
ZendService\Technorati\CosmosResult
extends ZendService\Technorati\Result
<zendservice.technorati.classes.result>
.
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 ZendService\Technorati\SearchResultSet
<zendservice.technorati.classes.searchresultset>
object.
Note
ZendService\Technorati\SearchResult
extends ZendService\Technorati\Result
<zendservice.technorati.classes.result>
.
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 ZendService\Technorati\TagResultSet
<zendservice.technorati.classes.tagresultset>
object.
Note
ZendService\Technorati\TagResult
extends ZendService\Technorati\Result
<zendservice.technorati.classes.result>
.
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 ZendService\Technorati\DailyCountsResultSet <zendservice.technorati.classes.dailycountsresultset>
object.
Note
ZendService\Technorati\DailyCountsResult
extends ZendService\Technorati\Result
<zendservice.technorati.classes.result>
.
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 ZendService\Technorati\TagsResultSet <zendservice.technorati.classes.tagsresultset>
object.
Note
ZendService\Technorati\TagsResult
extends ZendService\Technorati\Result
<zendservice.technorati.classes.result>
.
ZendService\Technorati\GetInfoResult
represents a single Technorati GetInfo query result object.
ZendService\Technorati\BlogInfoResult
represents a single Technorati BlogInfo query result object.
ZendService\Technorati\KeyInfoResult
represents a single Technorati KeyInfo query result object. It provides information about your Technorati API Key daily usage <zendservice.technorati.checking-api-daily-usage>
.