Amazon with Symfony
Posted on 7月 2nd, 2007 by sudabon
YouTube with Symfonyと同様、PEARを使わずにAmazon ECS Webサービスをsymfonyで利用する方法をメモしておきます。
class bookComponents extends sfComponents { public function executeDefault() { $apikey = "YOUR_API_KEI"; $asocid = "YOUR_ASSOCIATE_ID"; $url = sfConfig::get('app_book_url') . "Service=AWSECommerceService&AWSAccessKeyId=" . $apikey . "&AssociateTag=" . $asocid . "&ResponseGroup=Large&Operation=ItemSearch&SearchIndex=Books&locale=JP&Sort=daterank&Version=2007-05-14&BrowseNode=499986"; $res = file_get_contents($url); $xml = simplexml_load_string($res); $this->books = array(); foreach ($xml->Items->Item as $item) { $book_data = (array)$item; $isbn = $book_data['ASIN']; $url = $book_data['DetailPageURL']; $book_attr = (array)$book_data['ItemAttributes']; if (isset($book_attr['Author'])) { if (is_array($book_attr['Author'])) { $author = htmlspecialchars($book_attr['Author'][0], ENT_QUOTES); } else { $author = htmlspecialchars($book_attr['Author'], ENT_QUOTES); } } else { $author = ""; } $title = htmlspecialchars($book_attr['Title'], ENT_QUOTES); $date = $book_attr['PublicationDate']; if (isset($book_attr['Publisher'])) { $publisher = htmlspecialchars($book_attr['Publisher'], ENT_QUOTES); } else { $publisher = ""; } $book_price = (array)$book_attr['ListPrice']; $price = $book_price['Amount']; if (isset($book_data['SmallImage'])) { $book_image = (array)$book_data['SmallImage']; $image_url = $book_image['URL']; } else { $image_url = ""; } $book_items = array('isbn'=>$isbn, 'url'=>$url, 'title'=>$title, 'author'=>$author, 'price'=>$price, 'publisher'=>$publisher, 'date'=>$date, 'thumbnail_url'=>$image_url); array_push($this->books, $book_items); } } }
このコードはドッグランファン(廃止)で利用しています。
Filed under: Webフレームワーク

