dongshen9686 2016-01-12 23:35
浏览 89

如何更改此Amazon Product Advertising API PHP连接以搜索ISBN


I am using a PHP class to interact with the Amazon Product advertising API. I need to be able to look up books (ISBN numbers) however this class does not seem to support it. I have attempted to modify the keywords function to accept ISBN number however I have had no luck. Would anyone be able to point me in the right direction of a resource to learn how to do this, or if it's an easy fix show it to me? Thank you in advance

amazon_api_class.php

<?php  
    require_once 'aws_signed_request.php';

    class AmazonProductAPI
    {

        private $public_key     = "YOUR AMAZON ACCESS KEY ID";
        private $private_key    = "YOUR AMAZON SECRET KEY";

        /* 'Associate Tag' now required, effective from 25th Oct. 2011 */
        private $associate_tag  = "YOUR AMAZON ASSOCIATE TAG";

        const MUSIC = "Music";
        const DVD   = "DVD";
        const GAMES = "VideoGames";

        private function verifyXmlResponse($response)
        {
            if ($response === False)
            {
                throw new Exception("Could not connect to Amazon");
            }
            else
            {
                if (isset($response->Items->Item->ItemAttributes->Title))
                {
                    return ($response);
                }
                else
                {
                    throw new Exception("Invalid xml response.");
                }
            }
        }

        private function queryAmazon($parameters)
        {
            return aws_signed_request("com",
                                      $parameters,
                                      $this->public_key,
                                      $this->private_key,
                                      $this->associate_tag);
        }

        public function searchProducts($search,$category,$searchType="UPC")
        {
            $allowedTypes = array("UPC", "TITLE", "ARTIST", "KEYWORD");
            $allowedCategories = array("Music", "DVD", "VideoGames");

            switch($searchType) 
            {
                case "UPC" :
                    $parameters = array("Operation"     => "ItemLookup",
                                        "ItemId"        => $search,
                                        "SearchIndex"   => $category,
                                        "IdType"        => "UPC",
                                        "ResponseGroup" => "Medium");
                                break;

                case "TITLE" :
                    $parameters = array("Operation"     => "ItemSearch",
                                        "Title"         => $search,
                                        "SearchIndex"   => $category,
                                        "ResponseGroup" => "Medium");
                                break;

            }

            $xml_response = $this->queryAmazon($parameters);

            return $this->verifyXmlResponse($xml_response);

        }

        public function getItemByUpc($upc_code, $product_type)
        {
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $upc_code,
                                "SearchIndex"   => $product_type,
                                "IdType"        => "UPC",
                                "ResponseGroup" => "Medium");

            $xml_response = $this->queryAmazon($parameters);

            return $this->verifyXmlResponse($xml_response);

        }

        public function getItemByAsin($asin_code)
        {
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $asin_code,
                                "ResponseGroup" => "Medium");

            $xml_response = $this->queryAmazon($parameters);

            return $this->verifyXmlResponse($xml_response);
        }

        public function getItemByKeyword($keyword, $product_type)
        {
            $parameters = array("Operation"   => "ItemSearch",
                                "Keywords"    => $keyword,
                                "SearchIndex" => $product_type);

            $xml_response = $this->queryAmazon($parameters);

            return $this->verifyXmlResponse($xml_response);
        }

    }

    ?>
  • 写回答

1条回答 默认 最新

  • dongzhu7329 2016-01-28 23:09
    关注

    Lookup by ISBN requires setting the IdType parameter to ISBN. Extending your code might look like this:

      public function getItemByISBN($isbn)
        {
            $parameters = array("Operation"     => "ItemLookup",
                                "ItemId"        => $isbn,
                                "IdType"        => "ISBN"
                                "ResponseGroup" => "Medium");
    
            $xml_response = $this->queryAmazon($parameters);
    
            return $this->verifyXmlResponse($xml_response);
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装