seetheworldsecond Posted June 27, 2011 Share Posted June 27, 2011 Hi, I am new to php and I am using it with xml to work with the ebay api. I am trying to run 2 ebay api calls, I need one to capture and use the data from the other. The goal is getting results using FindPopularItems Api call and then makes another API call to GetMultipleItems with a list of item IDs returned from FindPopularItems. This is what I have come up with so far... <?php error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging $query = $_POST['search']; // You will need to supply your own query $endpoint = 'http://open.api.ebay.com/shopping'; // URL to call $responseEncoding = 'XML'; // Type of response we want back // Construct the FindPopularItems call $apicall = "$endpoint?callname=FindPopularItems&responseencoding=$responseEncoding&appid=ApiKey&siteid=0& QueryKeywords=$query&MaxEntries=5&version=725"; // Load the call and capture the document returned by eBay API $resp = simplexml_load_file($apicall); // Check to see if the response was loaded, else print an error if ($resp) { $results = ''; // If the response was loaded, parse it and build links foreach($resp->ItemArray->Item as $item) { $link = $item->ViewItemURLForNaturalSearch; $title = $item->Title; $watchcount = $item->WatchCount; $image = $item->GalleryURL; $itemid = $item->ItemID; // For each SearchResultItem node, build a link and append it to $results $results .= "<div id=\"container\"> <div id=\"image\"> <img src=\"$image\" /> </div> <div id=\"tophalf\"> <center> <p> <span class=\"title\">$title</span> <br /> <span class=\"black\">Date this item ends for sale:</span><span class=\"red\">June.30.2011</span> </p> </center> </div> <div id=\"bottomhalf\"> <img src=\"itemswatched.jpg\" width=\"36\" height=\"31\" /> <span class=\"black2\">Items Watched by:<b>$watchcount</b> people. Items Sold $itemid </span><img src=\"money.jpg\" width=\"50\" height=\"30\" /> <span class=\"black2\">Price:</span>$1.49 </div> </div>"; } } // If there was no response, print an error else { $results = "Oops! Must not have gotten the response!"; } // Construct the GetSingleItem call $apicallb = "$endpoint?callname=GetSingleItem&responseencoding=XML&appid=apiKey&siteid=0&ItemID=$itemid& IncludeSelector=Details&version=723"; // Load the call and capture the document returned by eBay API $Resp = simplexml_load_file($apicallb); // Check to see if the response was loaded, else print an error if ($Resp) { $results2 = ''; // If the response was loaded, parse it and build links foreach($Resp->Item as $item2) { $qsold = $item2->QuantitySold; // For each SearchResultItem node, build a link and append it to $results $results2 .= "Q Sold: $qsold<br/>"; } } // If there was no response, print an error else { $results2 = "Oops! Must not have gotten the response!"; } ?> <!-- Build the HTML page with values from the call response --> <html> <head> <link href="css.css" rel="stylesheet" type="text/css" /> <title> eBay Search Results for <?php echo $query; ?> </title> </head> <body> <h1>eBay Search Results for <?php echo $query; ?></h1> <form action="Sample_gmwi_gsi_grci_NV_XML.php" method="POST"> Search Popular ebay Items <input type="text" name="search" /> <input type="submit" /> </form> <?php echo $results,$qsold;?> </body> </html> Please visit and search for something at the following url http://development-zone.info/example.html , it is here were you can see this code in action once something is searched. Please help on how I can reconstruct the code to use these two ebay Api's properly. Thank you very much for your time. Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/ Share on other sites More sharing options...
gizmola Posted June 27, 2011 Share Posted June 27, 2011 You can foreach through a structure multiple times. The first time you foreach through, assemble a list of the itemids you need. One method could be to do: $items = array(); foreach($resp->ItemArray->Item as $item) { $items[] = $item->ItemID; } I'm not familiar with the api, but you should be able to figure out how to use this to send it to GetMultipleItems. Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/#findComment-1235587 Share on other sites More sharing options...
seetheworldsecond Posted June 28, 2011 Author Share Posted June 28, 2011 You can foreach through a structure multiple times. The first time you foreach through, assemble a list of the itemids you need. One method could be to do: $items = array(); foreach($resp->ItemArray->Item as $item) { $items[] = $item->ItemID; } I'm not familiar with the api, but you should be able to figure out how to use this to send it to GetMultipleItems. Hello gizmola, Thank you very much for your input, I feel like because of it I am closer then ever from being able to get this to work properly. I have placed the piece of code into my code and updated it, however now the only thing left is being able to place all these ItemIds into one single variable, The goal now is to be able to use my ebay api call to use each of these itemids. $apicallb = "$endpoint?callname=GetSingleItem&responseencoding=XML&appid=JesusSan-7670-47ee-a5fa-5ef5fb981d5a&siteid=0&ItemID=$items[0]&IncludeSelector=Details&version=723"; Above is the apicall, $items[0] is being used for now, it will of course only pull that itemid from that position in the array, I need a way to pull them all though in use it in this api call above. I tried just placing $items and it has given be the below error so I know thats not going to work so there must be another method I am missing since I am so new to php. "Notice: Undefined variable: qsold in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 113" Thanks gizmola and whoever else who provides a helping hand, I really do appreciate your time. Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/#findComment-1235716 Share on other sites More sharing options...
jcbones Posted June 28, 2011 Share Posted June 28, 2011 So, being un-familiar with the ebay API. Does it accept item id's as a comma separated list? OR, do you have to call each item id individually? There are a lot of way to get the id's back from an array. $comma_separated_list = implode(',',$items); Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/#findComment-1235718 Share on other sites More sharing options...
seetheworldsecond Posted June 28, 2011 Author Share Posted June 28, 2011 So, being un-familiar with the ebay API. Does it accept item id's as a comma separated list? OR, do you have to call each item id individually? There are a lot of way to get the id's back from an array. $comma_separated_list = implode(',',$items); Hi jcbones, Here is some more information about this ebay api call "The item ID that uniquely identifies the item listing for which to retrieve the data. You can provide a maximum of 20 item IDs. When making a URL request, repeating ItemID parameters must be specified as an indexed array (e.g., ...&ItemID(0)=130310421484&ItemID(1)= 300321408208& ItemID(2)=370214653822...). Alternatively, as a shortcut for URL requests, you can specify the item IDs as a comma-separated list in a single ItemID parameter (e.g., ...< code>&ItemID=130310421484,300321408208,370214653822... ) for convenience." I have used your code and I can't seem to get it work, even tho your code does look like the solution...ehh I wonder what I could be doing wrong now...Nonetheless thank you very much, I feel like I am slowly getting closer every bit by bit. Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/#findComment-1235727 Share on other sites More sharing options...
seetheworldsecond Posted June 28, 2011 Author Share Posted June 28, 2011 Hi i just wanted to thank everyone for their support, and thank the owners of this beautiful community. It turns out I was using the wrong call, to only call single items this is why the api call was not working with multiple ItemIds, now that I switched over to the Multiple item call everything is perfect now! Problem Solved! Quote Link to comment https://forums.phpfreaks.com/topic/240497-help-please-new-at-php-and-ran-into-an-issue/#findComment-1235737 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.