Search the web
Sign In
New User? Sign Up
yws-shopping · Yahoo! Shopping Developer Support Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
The request failed   Message List  
Reply | Forward Message #222 of 242 |
The request failed

Hello

I am getting this error "The request failed" while product search. My script is like this

<?php

error_reporting(E_ALL);

// The web services request
//$request =  'http://api.search.yahoo.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&query=Madonna&results=4';
$request =  'http://api.shopping.yahoo.com/ShoppingService/v1/productSearch?appid=YahooDemo&query=Madonna&results=4';

// Fetch it
$response = file_get_contents($request);

if ($response === false) {
 die('The request failed');
}

// Create a new DOM object
$dom = new DOMDocument('1.0', 'UTF-8');

// Load the XML into the DOM
if ($dom->loadXML($response) === false) {
    die('Parsing failed');
}

// Now traverse the DOM with this function.
// This traversal function is suitable for the Yahoo! Maps and
// Search web services, and any other Yahoo! Web Services that
// return the number of results as attributes in the root tag and
// have no other attributes in the results. For other Yahoo! Web
// Services, such as Flickr web services, this routine will
// have to be altered.
function xml_to_result($dom) {
 $root = $dom->firstChild;
 foreach($root->attributes as $attr) $res[$attr->name] = $attr->value;
 $node = $root->firstChild;
 $i = 0;
 while($node) {
  switch($node->nodeName) {
   case 'Result':
    $subnode = $node->firstChild;
    while($subnode) {
     $subnodes = $subnode->childNodes;
     foreach($subnodes as $n) {
      if($n->hasChildNodes()) {
       foreach($n->childNodes as $cn) $res[$i][$subnode->nodeName][$n->nodeName]=trim($cn->nodeValue);
      } else $res[$i][$subnode->nodeName]=trim($n->nodeValue);
     }
     $subnode = $subnode->nextSibling;
    }
    break;
   default:
    $res[$node->nodeName] = trim($node->nodeValue);
    $i--;
    break;
  }
  $i++;
  $node = $node->nextSibling;
 }
 return $res;
}

$res = xml_to_result($dom);

echo '<pre>';
print_r($res);
echo '</pre>';

?>

above script works well for 'http://api.search.yahoo.com/ImageSearchService/V1/imageSearch

Please help me to solve this problem

 



Mon Apr 30, 2007 11:09 am

pkumar125
Offline Offline
Send Email Send Email

Forward
Message #222 of 242 |
Expand Messages Author Sort by Date

Hello I am getting this error <b>"The request failed"</b> my script works fine with images,news,video and webs but not working for product search. Please help...
pkumar125
Offline Send Email
May 13, 2007
12:15 am

Hello I am getting this error "The request failed" while product search. My script is like this <?php error_reporting(E_ALL); // The web services request ...
pkumar125
Offline Send Email
May 13, 2007
12:15 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help