Browsing Category: "tutorial"

Yahoo! Image Search REST API - Flex example

Flex, tutorial June 20th, 2007

I’ve written a small example to show how to call REST services from Flex.

See working example: click here

Source code: click here

Flex Yahoo! Image Search REST Sample

The sample is source code enabled.
Accessing REST services with Flex is pretty simple. The main work done in the code is done by the following code:

<mx:HTTPService id=”yahoo_image_search”
url=”http://search.yahooapis.com/ImageSearchService/V1/imageSearch”>
<mx:request>
<appid>get your id from yahoo</appid>
<query>{input.text}</query>
</mx:request>
</mx:HTTPService>

Here we are calling the REST API with HTTP Service and passing it two required parameters:
appid - The application ID. See Application IDs for more information.
query - The query to search for. Use + to include terms, - to exclude terms, and put quotes around “exact phrase”.

You can find the complete description of the Yahoo! Image Search API here - http://developer.yahoo.com/search/image/V1/imageSearch.html

The response returned by the API is in XML format:

<ResultSet xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns=”urn:yahoo:srchmi” xsi:schemaLocation=”urn:yahoo:srchmi http://search.yahooapis.com/ImageSearchService/V1/ImageSearchResponse.xsd” totalResultsAvailable=”190145″ totalResultsReturned=”2″ firstResultPosition=”1″>
<Result>
<Title>Madonna photo Madonna 6200315</Title>
<Summary />
<Url>
http://www.poster.net/madonna/madonna-photo-madonna-6200315.jpg</Url>

Hence, to access the main results we need to access the <Result> node inside of <ResultSet>, which is pretty state forward with our Datagrid.

blank