How to Grab Amazon XML and Post to Your Blog / Site

I will continue my articles about build amazon affiliate store, and that will be the focus of this article is How to Grab Amazon XML and Post to Your Blog / Site ? . After we get Amazon XML url with API ,  we can get amazon data from that URL. Use this example to get amazon xml url.

I think we all already know how to take the xml data. So I do not need to explain in detail

$A='Your Amazon Xml Url';
if (!@simplexml_load_file($A))
{
 echo 'Link tidak valid';
}else
{
  $xml = simplexml_load_file($A);
  $dd=$xml->Items->Item;
  if( !empty($dd))
  {
   $asin='';
   $mediumimage='';
   $largeimage='';
   $detailpage='';
   $feature='';
   $brand='';
   $binding='';
   $listprc='';
   $title='';
   $harga='';
   $custrev='';
   $review='';
   $Manufacturer='';
   $tag='';
   foreach($dd->children() as $child)
   {
    if ($child->getName()=='ASIN')
    { $asin=$child;}
    if ($child->getName()=='DetailPageURL')
    { $detailpage=$child;}
    if ($child->getName()=='LargeImage')
    {
      foreach($child->children() as $url)
      {
        if ($url->getName() == 'URL')
        {$largeimage=$url;}
      }
    }
    if ($child->getName()=='ItemAttributes')
    {
      foreach($child->children() as $url)
      {
        if ($url->getName() == 'Manufacturer')
        { $Manufacturer = $url;}
        if ($url->getName() == 'Binding')
        { $binding=$url;}
        if ($url->getName() == 'Brand')
        { $brand=$url; }
        if ($url->getName() == 'Feature')
        { $feature=$feature.$url.','; }
        if ($url->getName() == 'ListPrice')
        {
           foreach($url->children() as $listprice)
           {
             if ($listprice->getName()== 'FormattedPrice' )
             { $listprc=$listprice; }
           }
        }
        if ($url->getName() == 'Title')
        { $title=$url; }
     }
   }
   if ($child->getName()=='Offers')
   {
     foreach($child->children() as $Offers)
     {
       if ($Offers->getName()=='Offer')
       {
         foreach($Offers->children() as $offer)
         {
           if($offer->getName() == 'OfferListing')
           {
             foreach($offer->children() as $OfferListing)
             {
               if($OfferListing->getName() == 'Price')
              {
                foreach($OfferListing->children() as $Price)
                {
                  if($Price->getName() == 'FormattedPrice')
                  { $harga=$Price; }
                }
              }
             }
           }
         }
       }
     }
   }
 if ($child->getName()=='CustomerReviews')
 {
   foreach($child->children() as $url)
   {
     if ($url->getName() == 'IFrameURL')
     { $custrev=$url; }
   }
 }
 if ($child->getName()== 'EditorialReviews')
 {
   foreach($child->children() as $EditorialReviews)
   {
     if ($EditorialReviews->getName() == 'EditorialReview')
     {
        foreach($EditorialReviews->children() as $EditorialReview)
        {
          if ($EditorialReview->getName() == 'Content')
          { $feature=$feature.'<div>'.$EditorialReview.'</div>';
        }
     }
   }
 }
//put your template layout here

//end layout
}
else
{
 $dd=$xml->Items->Request->Errors->Error;
 $result='';
 foreach($dd->children() as $child)
 {
   $result=$result.$child.'<br/>';
 }
 return 'Server response : <br/>'.$result;
}

For Post layout or template, You can creation according to your wishes, As follows is a snippet of my coding


$result='<div id="kotak" style="width: 60%; height="auto" position: relative;border: 0px #000 solid;" align="center"><div style="border: 0px #000 solid; width: 200px; float: left; height: auto; overflow: hidden; text-align: center; margin-bottom: 10px; position: relative;" align="center"><a href="'.$detailpage.'"><img title="'.$title.'" class="aligncenter" alt="" src="'.$largeimage.'" width="75%" height="auto" /></a></div><div id="row-price" style="border: 0px #000 solid; padding-bottom: 5px; margin-bottom: 10px; overflow: hidden;"><img style="letter-spacing: 0.05em; line-height: 1.6875;" alt="rating" src="'.$urlrating.'" align="left" /><div style="width: 100%; height: 31px;">';
if ($listprc<>'')
{
$result=$result.'<div style="width: 80%; height:auto; text-align: left; float: left;padding-left: 10px; padding-top: 10px;padding-bottom: 10px; margin-top:30px; background-color: #0c6; color: #fff;"><span style="text-decoration: line-through; font: 1.8em "gothamMed";"> Reg Price : '.$listprc.'</span></div>';
}
$result=$result.'</div><div style="font: bold 2.8em ;font-size: 32px; text-align: right; border: 1px solid #ececec; width: 95%; margin-top:10px; float: right;">PRICE : <a href="'.$detailpage.'" title="Click here to check new price from Amazon.com">'.$harga.'</a></div><div class="clear"></div></div><div style="text-align: right; width: 95%; font-size: 10px;">"This Best "<b>'.$title.'</b>" Selling Tends to SELL OUT VERY FAST! MUST HAVE product, be sure to Order Now to avoid disappointment!* Discount only for limited time, <a href="'.$detailpage.'">Buy it now!</a><br/><br/><br/></div><div style="width: 100%;" align="right"><a target="_blank" href="'.$detailpage.'"><img alt="" src="http://1.bp.blogspot.com/-9cgBG-AayzQ/U-BX1prV1RI/AAAAAAAAABc/cGUkntL_jtY/s1600/todayprice.gif" title="Get Special Price at Amazon Now" align="right"/></a></div><div style="width: 100%; float: left;"><div id="tabs" style="list-style: none; overflow: hidden;"><div style="display: block; float: left; border-top: 1px solid transparent; background: #096; padding: 10px 18px; color: #fff; margin-right: 2px;">PRODUCT REVIEW</div></div><span style="color: #333333; font-size: 1.5em; letter-spacing: 0.05em; line-height: 1.6875;">'.$title.'</span><div><img class="slickr-post" alt="'.$title.'" src="'.$largeimage.'" width="20%" title="'.$title.'" /><div style="text-align:justify; ">'.$feature.'</div><a target="_blank" href="'.$detailpage.'"><img alt="" src="http://1.bp.blogspot.com/-3ne0N4K6fJM/U-BX11PZrNI/AAAAAAAAABg/rZWJXoX7kEA/s1600/buy-from-amazon-us.png" title="Get Special Price at Amazon Now" /></a></div><iframe frameborder="0" style="margin-top: 10px;" src="'.$custrev.'" width="100%" height="500px"><p>Your browser does not support iframes.</p></iframe></div></div>';
$hasil='<b>AMAZON Product XML DATA URL :</b> <br/><br/><textarea id="dataarray" rows="5" cols="80">'.$A.'</textarea><br/><br/> <b>LAYOUT HTML CODE : (Copy below url to your post)</b> <br/><br/><textarea id="dataarray" rows="10" cols="80">'.$result.'</textarea><br/><br/> <b>LAYOUT DISPLAY PRODUCT :</b> <br/><br/>'.$result;
return $hasil;

 Try the Grab Amazon XML tools here

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

6 Comments

 Add your comment
  1. Mas Sigit, saya mau nanya. Semoga mas berkenan menjawab.
    Template untuk layout saya pastekan di baris 112
    Kemudian pada baris 1 saya berikan kode php pembuka dan baris 125 dengan kode php penutup.
    Namun setelah di running (saya menggunakan XAMPP di localhost) muncul error
    Parse error: syntax error, unexpected end of file in
    itu apanya ya mas?
    Terima kasih

  2. mas, kok muncul ini ya mas?
    Fatal error: Call to a member function children() on a non-object in /home/minionthemes/public_html/amazon/index.php on line 119? mohon bantuannya mas 🙁

  3. gan, saya coba tool asin grabber-ny disni http://seegatesite.com/tools/azongrabber.php kok tidak muncul ASIN id-nya ya?

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: