PHP
  Home arrow PHP arrow Page 4 - Using Yahoo! Web Services with PHP 5
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 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? 
PHP

Using Yahoo! Web Services with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Using Yahoo! Web Services with PHP 5 - Querying the Yahoo! Image Search Service with PHP 5
    (Page 4 of 4 )

    As I explained in the section that you just read, the last hands-on example that I’m going to show you in this article will be aimed at demonstrating how to query the Yahoo! Image Search Service directly from inside a simple PHP 5 script.

    Logically, this procedure is nearly identical to the one discussed in the prior section. Its main difference rests on the URL where the web service in question has to be queried. But let me go straight to the point and show you how to use this helpful Yahoo! Service with PHP 5. Take a look at the following code sample:


    try{

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

    $request='http://search.yahooapis.com/ImageSearchService/V1/
    imageSearch?appid=Your-AP-ID&query=madonna&results=2';

    // 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();

    }


    // displays the following

    /*

    <ResultSet xsi:schemaLocation="urn:yahoo:srchmi
    http://api.search.yahoo.com/ImageSearchService/V1/
    ImageSearchResponse.xsd" totalResultsAvailable="684079"
    totalResultsReturned="2" firstResultPosition="1">

    <Result>

    <Title>Madonna_vogue.jpg</Title>

    <Summary>Madonna_3.jpg 30-Apr-2005 14:34 23k Madonna_9.jpg 30-
    Apr-2005 14:34 23k Madonna_vogue.jpg 30-Apr-2005 14:35 22k
    Madonna_13.jpg 30-Apr-2005 14:34 22k</Summary>

    <Url>http://www.multinet.no/~jonarne/Hjemmesia/Favorittartister/
    madonna/Madonna_vogue.jpg</Url>

    <ClickUrl>http://www.multinet.no/~jonarne/Hjemmesia/
    Favorittartister/madonna/Madonna_vogue.jpg</ClickUrl>

    <RefererUrl>http://www.multinet.no/~jonarne/Hjemmesia/
    Favorittartister/madonna?S=D</RefererUrl>

    <FileSize>22835</FileSize>

    <FileFormat>jpeg</FileFormat>

    <Height>409</Height>

    <Width>299</Width>

    <Thumbnail>

    <Url>http://sp1.mm-a7.yimg.com/image/3729207548</Url>

    <Height>140</Height>

    <Width>102</Width>

    </Thumbnail>

    </Result>

    <Result>

    <Title>madonna_90563a.jpg</Title>

    <Summary>ANGRER: Madonna spiller gjerne pa sex for a provosere, men angrer pa boken Sex.- Jeg lurer stadig pa hva som motiverte meg til a lage den, sier hun om sin vagale bok, Sex , som vakte</Summary>

    <Url>http://pub.tv2.no/multimedia/TV2/archive/00090/
    madonna_90563a.jpg</Url>

    <ClickUrl>http://pub.tv2.no/multimedia/TV2/archive/00090/
    madonna_90563a.jpg</ClickUrl>

    <RefererUrl>http://pub.tv2.no/TV2/underholdning/kjendiser/
    madonna/article104130.ece</RefererUrl>

    <FileSize>14540</FileSize>

    <FileFormat>jpeg</FileFormat>

    <Height>400</Height>

    <Width>200</Width>

    <Thumbnail>

    <Url>http://sp1.mm-a4.yimg.com/image/2804555704</Url>

    <Height>135</Height>

    <Width>67</Width>

    </Thumbnail>

    </Result>

    </ResultSet>

    <!--

    ws05.search.scd.yahoo.com uncompressed/chunked Wed Oct 17
    08:02:55 PDT 2007

    -->


    As demonstrated above, using the Yahoo! Image Search Service with PHP 5 requires practically the same steps that you learned when using other web services. In this case, the pertinent results are retrieved by using the same “file_get_contents()” PHP native function that you saw before, and are also displayed on the browser in raw XML format.

    Finally, taking into account that all of the code samples included in this tutorial might be the first ones that you learned concerning the implementation of the most common web services offered by Yahoo! with PHP 5, I suggest you to develop your own test examples to acquire a more solid background in this useful and interesting topic.

    Final thoughts

    That’s it for now. In this initial installment of the series, I showed you with some educational code samples how to query basically the four primary web search services provided by Yahoo! directly with PHP 5. As you saw earlier, in every case the corresponding search results were outputted in XML, but this is only momentary.

    I’m saying this because in the next tutorial of the series I’m going to teach you how to utilize all these Yahoo! APIs to work specifically with PHP, and display the results returned by a given search query in the form of serialized arrays.

    Now that you know what the upcoming part will be about, you won’t want to miss it!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · The implementation of different web services with PHP 5 can be sometimes, a...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway