The following sections provide you with examples of using the
different feature sets of Services_Yahoo.
Currently this includes documentation for the interfaces to
Yahoo!
Search and Content
Analysis.
All public methods in Services_Yahoo have in
common that exceptions
will be raised when something goes wrong. This is why try {
... } catch { } blocks are wrapped around all examples.
Note:
The examples are designed to be run from a command line shell. If
you would like to test them in a web browser you should replace
\n with <br /> for
better readability.
Speaking to Yahoo! Search
The following examples will communicate with Yahoo! Search.
Note:
In order to query the Image, News, Video or Local search, one only
needs to replace the argument "web" in the call of the
factory() method with one of
"image", "news", "video", or
"local".
Using the Yahoo! Content Analysis services
The following examples will show you how to use the Content Analysis
Services provided by Yahoo!.
require_once "Services/Yahoo/ContentAnalysis.php";
try {
$search = Services_Yahoo_ContentAnalysis::factory("termExtraction");
$search->setContext("Italian sculptors and painters of the "
. "renaissance favored the Virgin Mary for inspiration.");
$search->setQuery("madonna");
$results = $search->submit();
foreach ($results as $result) {
echo $result . "\n";
}
} catch (Services_Yahoo_Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
foreach ($e->getErrors() as $error) {
echo "* " . $error . "\n";
}
}
It is possible to skip the call to setQuery().
The parameter set by this method is intended to help the engine with
the extraction process, but it is not stricly required.