php - Getting multiple items from eBay with Single item API shows ERROR -


i'm using ebay single item api details selected items. know ebay have multiple-item api not give details want.


i have var $gpd have item numbers. using explode make array $items

then using foreach run ebay single item api items in array.

then added 20% profit , roundup price.

then making static paypal button.


my code below works perfect of time. shows 2 first items in array , shows error:

$xml=simplexml_load_string($response) or die("error: not item"); 

if again reload page shows items in array , works perfectly.

here code:

<?php $gpd = '281616878215, 221694130228, 191506118709, 271806308878, 231451119156' ; $items = explode(', ', $gpd); $profit = "1.2"; function round_up ($value, $places=0) {   if ($places < 0) { $places = 0; }   $mult = pow(10, $places);   return ceil($value * $mult) / $mult; }  foreach($items $item) { $appid = 'here-need-to-put-ebay-appid'; $exexex = $item; $request = '<?xml version="1.0" encoding="utf-8"?>             <getsingleitemrequest xmlns="urn:ebay:apis:eblbasecomponents" >             <itemid>'.$exexex.'</itemid>             <includeselector>details,shippingcosts,itemspecifics,variations</includeselector>             </getsingleitemrequest>'; $callname = 'getsingleitem'; $compatibilitylevel = 647; $endpoint = "http://open.api.ebay.com/shopping"; $headers[] = "x-ebay-api-call-name: $callname"; $headers[] = "x-ebay-api-app-id: $appid"; $headers[] = "x-ebay-api-version: $compatibilitylevel"; $headers[] = "x-ebay-api-request-encoding: xml"; $headers[] = "x-ebay-api-response-encoding: xml"; $headers[] = "x-ebay-api-site-id: 0"; $headers[] = "content-type: text/xml";  $curl = curl_init($endpoint); curl_setopt($curl, curlopt_ssl_verifypeer, false); curl_setopt($curl, curlopt_ssl_verifyhost, false); curl_setopt($curl, curlopt_returntransfer, 1); curl_setopt($curl, curlopt_post, 1); curl_setopt($curl, curlopt_httpheader, $headers); curl_setopt($curl, curlopt_postfields, $request);  $response = curl_exec($curl); $data = simplexml_load_string($response) ;  $ackresponse = $data->ack ;  $xml=simplexml_load_string($response) or die("error: not item"); $itemvalueprice = (float)$data->item->convertedcurrentprice; $itemprice = $itemvalueprice * $profit; $price = round_up ($itemprice, 1); $paybutton = '<form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="my@paypal.com"> <input type="hidden" name="currency_code" value="usd"> <input type="hidden" name="item_name" value="' . htmlentities($data->item->title, ent_quotes) . '"> <input type="hidden" name="amount" value="' . $price . '"><input type="hidden" name="on0" value="imei"><input type="text" name="os0" > <br /> <input type="image" src="ordernow.jpg" border="0" name="submit" alt="paypal - safer, easier way pay online!"> </form>' ; $endt = str_replace(".000z", "", $data->item->endtime); $endtime = explode(t,$endt); $startt = str_replace(".000z", "", $data->item->starttime); $starttime = explode(t,$startt); $oldtrans = array('p','d','t','h','m','s'); $newtrans = array('<span class="red"> in </span>','d, ','','h ','m ','s'); $timeleft = str_replace($oldtrans,$newtrans,$data->item->timeleft);   echo '<h2>' . htmlentities($data->item->title, ent_quotes) . '</h2> <span>price <strong>' . $price . '</strong>$ </span> <span>sold <strong>' . $data->item->quantitysold . '</strong> </span> <span>score <strong>' . $data->item->seller-> positivefeedbackpercent . '</strong>% </span> <span><strong>' . $data->item->listingstatus . '</strong></span> <span><img src="' . $data->item->galleryurl . '" alt="' . htmlentities($data->item->title, ent_quotes) . '" /></span> <span>' . $paybutton . '</span><span>expires ' . $endtime[0] . '' . $timeleft . '</span> <br /><br />' ; } ?> 

my question why show error? if there error why show items of time? , error show 2 first items in array.

any idea how solve this?

thank helping.

there no difference between getsingle(multiple)items api call.

the getmultipleitems api call can take 20 items @ 1 go.

try this:

$appid = your_appid; $items = implode( ',', item_array);  // simpler using curl $xml = simplexml_load_file( "http://open.api.ebay.com/shopping?callname=getmultipleitems&responseencoding=xml&appid=your&siteid=0&version=897&itemid=$items&includeselector=details"); 

you can data specifying includeselector parameter.

http://developer.ebay.com/devzone/shopping/docs/callref/getmultipleitems.html#request.includeselector

getting quantitysold each item:

$ack = strtolower( ( string ) $xml->ack );  if( $ack == 'success' ) {     foreach( $xml->item $item ) {         echo "itemid - " . $item->itemid . '<br />';         echo "quantitysold - " . $item->quantitysold . '<br />';         echo '<br /><br />';     } } 

hope helps.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -