As I explained in the section that you just read, Yahoo! also provides PHP developers with a couple of powerful APIs that can be used within a given PHP 5 application to implement the popular video and image web search services with minor difficulties. As you’ll see in a few moments, these services can be easily queried by implementing practically the same programming logic that you learned in previous examples on this tutorial. This means that you shouldn’t have major problems putting the services to work for you. But it’s time to move on from this boring theory since I assume you’re hungry to see some concrete code samples, right? Thus, I’m going to begin by demonstrating how to invoke the helpful Yahoo! Video Search Service from a primitive PHP 5 script. It also will be capable of displaying the corresponding results in (X)HTML format. Now that I have explained how this brand new hands-on example is going to work, please pay attention to the following code sample to see the Yahoo! video search service in action: // example using Yahoo! Video Search Service - results are displayed in a basic (X)HTML format utilizing a procedural approach try{ $request='http://search.yahooapis.com/VideoSearchService/V1/videoSearch? // trigger the http request if(!$results=file_get_contents($request)){ throw new Exception('Error requesting Yahoo! Web service'); } $results=unserialize($results); foreach($results[ResultSet][Result] as $result){ echo '<h2>'.$result[Title].'</h2><p>'.$result[Summary].'</p><p><img } } catch(Exception $e){ echo $e->getMessage(); exit(); } As you can see, the above PHP 5 script has a signature that’s very similar to the one that I defined to query the Yahoo! Web Search. However, there are some slight differences here, because in this particular case I’m using the Yahoo API to implement its helpful video search service. This means that the URL where the respective HTTP request is triggered is obviously distinct. However, the rest of the script remains practically the same. The search results are first returned as a serialized PHP array and then displayed on the browser by using some basic (X)HTML tags. Besides, you should pay careful attention to the way that these results are extracted from the aforementioned array, since in this case I’m only interested in showing the pertinent titles, a brief summary on the retrieved video files, and the respective links. Also, to complement the previous explanation, below I included an unformatted version of these search results, so you can grasp more clearly how the previous script functions: // the following search results are displayed madonna_2004_montage.wmv Interviews, news footage and tour clips from New York and Paris....here's hoping 2005 is just as busy! Right Click And Save Target As Madonna's 2004 Movie Montage (WMV) - 7:44 - 21.8Mb Noticias madonna - Noticias madonna - Noticias madonna - http://madonnalicious.com/downloads/madonna_2004_montage.wmv madonna_earlscourt_190804.wmv http://www.madonnalicious.com/downloads/madonna_gelredome_090904.wmv http://www.madonnalicious.com/downloads/madonna_earlscourt_190804.wmv Indeed, after analyzing the prior hands-on example, you’ll have to agree with me that calling the powerful Yahoo! Image Search Service from your own PHP application is a straightforward process that can be tackled pretty effortlessly. And if you still have your doubts as to my claims, test the previous example on your web server (don’t forget to get an application ID first) and you’ll be amazed at how neatly it works! I think it’s time to move on, since I plan to show you yet another practical example focused primarily on demonstrating how to implement the Yahoo! Image Search Service in PHP 5. But as you might have guessed, this topic will be covered in detail in the upcoming section, so click on the link below and keep reading.
blog comments powered by Disqus |
|
|
|
|
|
|
|