PHP
  Home arrow PHP arrow Page 3 - Using Yahoo! Web Services with PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using Yahoo! Web Services with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2008-01-08


    Table of Contents:
  • Using Yahoo! Web Services with PHP 5
  • Getting started using the Yahoo! Web Search services
  • Implementing the Yahoo! Video Search Service with PHP 5
  • Querying the Yahoo! Image Search Service with PHP 5

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Yahoo! Web Services with PHP 5 - Implementing the Yahoo! Video Search Service with PHP 5
    ( Page 3 of 4 )

    In the previous section, you learned how to take advantage of the features offered by the Yahoo! Web Search Service, by coding only a simple PHP 5 script. Besides, once the pertinent service was queried with a sample search term, the corresponding results were returned to the browser in XML format, to be displayed on the browser.

    So, considering that you understood the basics of using this web service, I'm going to teach you how to code a similar script. It will be focused on utilizing another popular web service provided by Yahoo!, namely the one that searches video files.

    That being said, here’s the definition of this brand new script: 

    try{

    // example using Yahoo! Video Search Web Service - search results are displayed in raw XML format

    $request='http://search.yahooapis.com/VideoSearchService/V1/
    videoSearch?appid=Your-AP-ID&query=madonna&results=4';

    // trigger the http request

    if(!$results=file_get_contents($request)){

    throw new Exception('Error requesting Yahoo! Web service');

    }

    // display the results in XML format

    header('Content-type:text/xml;charset=iso-8859-1');

    echo $results;

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


     

    Definitely that wasn’t rocket science, right? As you can see, in this case I modified only the URL of the web service being requested, at the beginning of the script, in order to retrieve four different video files associated with the search term “Madonna.”

    Besides, since the script simply fetches these results in raw XML format, this is the output generated by it, after performing the pertinent search process:


    <ResultSet xsi:schemaLocation="urn:yahoo:srchmv
    http://api.search.yahoo.com/VideoSearchService/V1/
    VideoSearchResponse.xsd" totalResultsAvailable="10365"
    totalResultsReturned="4" firstResultPosition="1">

    <Result>

    <Title>madonna_2004_montage.wmv</Title>

    <Summary>, 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 </Summary>

    <Url>http://madonnalicious.com/downloads/
    madonna_2004_montage.wmv</Url>

    <ClickUrl>http://madonnalicious.com/downloads/
    madonna_2004_montage.wmv</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>22902293</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>464</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1702970034</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna_earlscourt_190804.wmv</Title>

     <Summary>http://www.madonnalicious.com/downloads/
    madonna_gelredome_090904.wmv madonna 9sep
    2004http://www.madonnalicious.com/downloads/
    madonna_earlscourt_190804.wmv
    http://www.madonnalicious.com/downloads/
    madonna_arlscourt_dtm_190804.wmv</Summary>

    <Url>http://www.madonnalicious.com/downloads/
    madonna_earlscourt_190804.wmv</Url>

    <ClickUrl>http://www.madonnalicious.com/downloads/
    madonna_earlscourt_190804.wmv</ClickUrl>

    <RefererUrl>http://lounge.cosmopolitan.nl/messages/1/14515.html?
    1095249265</RefererUrl>

     <FileSize>42149471</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>543</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1700163527</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna.al.et.mpg</Title>

    <Summary>Summary: Watch Madonna on Entertainment Tonight : Madonna discusses American Life with ET .mpg Noticias madonna - Noticias madonna - Noticias madonna -</Summary>

    <Url>http://steveswartz.com/madonna.al/madonna.al.et.mpg</Url>

    <ClickUrl>http://steveswartz.com/madonna.al/
    madonna.al.et.mpg</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>12821508</FileSize>

    <FileFormat>mpeg</FileFormat>

    <Height>240</Height>

    <Width>352</Width>

    <Duration>73</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1794815224</Url>

    <Height>98</Height>

    <Width>145</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna_jonathanross_ruperteverett.wmv</Title>

    <Summary>And Save Target As Friday Night With Jonathan Ross - Rupert Everett On Madonna (WMV) - 1:25 - 2.45Mb Noticias madonna Noticias madonna - Noticias madonna</Summary>

    <Url>http://www.madonnalicious.com/downloads/
    madonna_jonathanross_ruperteverett.wmv</Url>

    <ClickUrl>http://www.madonnalicious.com/downloads/
    madonna_jonathanross_ruperteverett.wmv</ClickUrl>

    <RefererUrl>http://www.descargaarchivos.com/noticias/index.php?
    query=madonna&type=video</RefererUrl>

    <FileSize>2579729</FileSize>

    <FileFormat>msmedia</FileFormat>

    <Height>240</Height>

    <Width>320</Width>

    <Duration>85</Duration>

    <Streaming>false</Streaming>

    <Channels>2</Channels>

    <Thumbnail>

    <Url>http://scd.mm-so.yimg.com/image/1703473304</Url>

    <Height>105</Height>

    <Width>140</Width>

    </Thumbnail>

    </Result>

    </ResultSet>

    <!--

    ws05.search.scd.yahoo.com uncompressed/chunked Wed Oct 17
    07:41:48 PDT 2007

    -->


    As shown above, the previous search returned the URL of four video files along with some additional information about them, such as their format and size, and the respective dimensions of the corresponding thumbnails as well.

    Again, it’s clear to see here that those search results can be easily formatted in (X)HTML, only using a few lines of PHP code, but as I expressed earlier, I will leave you this task as homework (if you’re having trouble sleeping, you may want to try this).

    All right, as you learned in the previous example, using the Yahoo! Video Search Service with PHP 5 is indeed a straightforward process that can be performed with minor hassles. Therefore it’s time to move on and code a final hands-on example. The example in question will be focused on querying the Yahoo! Image Search Service directly from a PHP 5 script.

    As you might have guessed, this procedure will be discussed in the upcoming section, so click on the below link and keep reading. 



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek