Monday, April 17, 2006

 

Yahoo Web Services Return Serialized PHP and PHP Developer

Yahoo! recently announced its new PHP Developer Center which can be found at: developer.yahoo.net/php and announced that many of their web services now return serialized PHP. You can read the announcement at developer.yahoo.net PHP developers will now be able to consume these web services even more easily than before.

REST web services now return serialized PHP by simply adding the "output=php" parameter to any web services request.

For example, suppose you want to search for PHP-related podcasts and return the first five results using Yahoo!'s Podcast Search web service http : //developer.yahoo.net/search/audio/V1/podcastSearch.html :


http://api.search.yahoo.com/AudioSearchService/V1/
podcastSearch?appid=YahooDemo&query=PHP&results=5
&output=php

The request above returns the results as serialized PHP. A simple PHP script can trivially parse the request using PHP's unserialize function which is built-in to all PHP4 and PHP5 implementations:


$request = 'http://api.search.yahoo.com/'
. 'AudioSearchService/V1/podcastSearch?'
. 'appid=YahooDemo&query=PHP&results=5&output=php';

$result = file_get_contents($request);
$phparray = unserialize($result);
echo '
';
print_r($phparray);
echo '
';
?>

(note: remove the extra backslash from the PRE tags for this to work)
For more information, and a complete list of Yahoo! developer APIs, check out the Yahoo! Developer Network web site at developer.yahoo.com

Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?