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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | $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
1 2 3 4 5 6 7 8 | $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="https://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="https://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; |
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
Mungkin copy kodenya ada yang kurang }, silahkan dicek lagi script milik mas wirja. 🙂
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 🙁
baris 119 nya mas dicky apa ya ? 🙂
gan, saya coba tool asin grabber-ny disni https://seegatesite.com/tools/azongrabber.php kok tidak muncul ASIN id-nya ya?
halo yudhi,
terimakasih sudah mencoba tools saya, kebetulan ada perubahan script html pada situs amazon, sehingga tutorial tersebut tidak bisa berjalan dengan baik. Silahkan coba tutorial yang ini https://seegatesite.com/easy-get-asin-with-my-amazon-asin-grabber-class/ , masih berfungsi dengan baik setelah saya coba.
terimakasih
can this be done in bulk?
you can do in bulk using looping 🙂