Amazon ECS API to fetch 1000 top selling books

前端 未结 4 372
感动是毒
感动是毒 2020-12-29 13:14

I need the API to fetch the top selling books on Amazon. By default it only fetches the top 10 items, but I need more than 10, near about 1000 items content by using single

4条回答
  •  自闭症患者
    2020-12-29 13:49

    3 && ($i-1)%2==0) )&& $i!=$len){
                    $m .=',';
                }
                $m .=$money[$i];
            }
            return strrev($m);
        }
        // Valid names that can be used for search
        private $mValidSearchNames = array(
            'All',
            'Apparel',
            'Appliances',
            'Automotive',
            'Baby',
            'Beauty',
            'Blended',
            'Books',
            'Classical',
            'DVD',
            'Electronics',
            'Grocery',
            'HealthPersonalCare',
            'HomeGarden',
            'HomeImprovement',
            'Jewelry',
            'KindleStore',
            'Kitchen',
            'Lighting',
            'Marketplace',
            'MP3Downloads',
            'Music',
            'MusicTracks',
            'MusicalInstruments',
            'OfficeProducts',
            'OutdoorLiving',
            'Outlet',
            'PetSupplies',
            'PCHardware',
            'Shoes',
            'Software',
            'SoftwareVideoGames',
            'SportingGoods',
            'Tools',
            'Toys',
            'VHS',
            'Video',
            'VideoGames',
            'Watches'
        );
    
        private $mErrors = array();
    
        public function __construct($urlBuilder, $outputType) {
            $this->urlBuilder = $urlBuilder;
            $this->dataTransformer = DataTransformerFactory::create($outputType);
        }
    
        public function GetValidSearchNames() {
            return $this->mValidSearchNames;
        }
    
        /**
         * Search for items
         *
         * @param   keywords            Keywords which we're requesting
         * @param   searchIndex         Name of search index (category) requested. NULL if searching all.
         * @param   sortBy              Category to sort by, only used if searchIndex is not 'All'
         * @param   condition           Condition of item. Valid conditions : Used, Collectible, Refurbished, All
         *
         * @return  mixed               SimpleXML object, array of data or false if failure.
         */
        public function ItemSearch($keywords,$itemPage, $searchIndex = NULL, $sortBy = NULL, $condition = 'All',$minPrice=50000,$maxPrice=55000) {
            ?>
             'ItemSearch',
                        'ResponseGroup' => 'Small,ItemAttributes,Offers,OfferSummary',
                        'Keywords' => $keywords,
                        'Condition' => $condition,
                        'ItemPage' => $itemPage,
                        'ListPrice' => $itemPage,
                        'MinimumPrice' => $minPrice,
                        'MaximumPrice' => $maxPrice,
                        'SearchIndex' => empty($searchIndex) ? 'All' : $searchIndex,
                        'Sort' => $sortBy && ($searchIndex != 'All') ? $sortBy : NULL
                    );
                    $totalPages=$this->FetchItems($params,$itemPage,$maxPrice,false);
                    if(($itemPage)==1)
                    {
                        $finished=true;
                        $itemPage=0;
                    }
                }
                $minPrice=$maxPrice;
                $maxPrice=$maxPrice+5000;
            }
            //echo "
    total Records : ".$this->item; ?>
    Title List Price Offer Price Offer Selling Price Amount Saved Brand Name Size Color Manufacturer


    ($itemPage-3) && $looper<($itemPage+3)) { if($looper==$itemPage) { $style="style='color:red;'"; echo "".$looper."   "; } else { echo "".$looper."   "; } }else if($looper>($totalPages-3)) { echo "".$looper."   "; }else if($looper>(($totalPages/2)-3) && $looper<(($totalPages/2)+3)) { echo "".$looper."   "; } } die(); //return $this->MakeAndParseRequest($params,$itemPage); } /** * Lookup items from ASINs * * @param asinList Either a single ASIN or an array of ASINs * @param onlyFromAmazon True if only requesting items from Amazon and not 3rd party vendors * * @return mixed SimpleXML object, array of data or false if failure. */ public function ItemLookup($asinList,$itemPage, $onlyFromAmazon = false) { $asinList="B01D0XDW1C"; if (is_array($asinList)) { $asinList = implode(',', $asinList); } $params = array( 'Operation' => 'ItemLookup', 'ResponseGroup' => 'ItemAttributes,Offers,Images', 'ReviewSort' => '-OverallRating', 'ItemId' => $asinList, 'MerchantId' => ($onlyFromAmazon == true) ? 'Amazon' : 'All' ); return $this->MakeAndParseRequest($params,$itemPage,true); } public function GetErrors() { return $this->mErrors; } private function AddError($error) { array_push($this->mErrors, $error); } public function FetchItems($params,$itemPage,$maxPrice,$lookup=false) { $signedUrl = $this->urlBuilder->generate($params); if($lookup) { try { $request = new CurlHttpRequest(); $response = $request->execute($signedUrl); $fileContents = str_replace(array("\n", "\r", "\t"), '', $response); $fileContents = trim(str_replace('"', "'", $fileContents)); $simpleXml = simplexml_load_string($fileContents); $json = json_encode($simpleXml); $decodedJson=json_decode($json,true); //print_r($decodedJson); print_r($decodedJson); die(); $parsedXml = simplexml_load_string($response); if ($parsedXml === false) { return false; } return $this->dataTransformer->execute($parsedXml); } catch(\Exception $error) { $this->AddError("Error downloading data : $signedUrl : " . $error->getMessage()); return false; } } else { try { $request = new CurlHttpRequest(); $response = $request->execute($signedUrl); $fileContents = str_replace(array("\n", "\r", "\t"), '', $response); $fileContents = trim(str_replace('"', "'", $fileContents)); $simpleXml = simplexml_load_string($fileContents); $json = json_encode($simpleXml); $decodedJson=json_decode($json,true); //print_r($decodedJson); //die(); if(isset($decodedJson['Items'])) { $this->perRequest=0; foreach($decodedJson['Items']['Item'] as $itm) { if(isset($itm['ItemAttributes']['ListPrice']['FormattedPrice'])) { $this->item=$this->item+1; $this->perRequest=$this->perRequest+1; ?> IND_money_format($savedAmount); $savedAmount="INR ".$savedAmount.".00"; ?> IND_money_format($savedAmount); $savedAmount="INR ".$savedAmount.".00"; ?> IND_money_format($savedAmount); $savedAmount="INR ".$savedAmount.".00"; ?> N/A N/A N/A "; } //echo "PerRequest : ".$this->perRequest."
    "; //die(); //$parsedXml = simplexml_load_string($response); //if ($parsedXml === false) { // return false; //} //return $this->dataTransformer->execute($parsedXml); } catch(\Exception $error) { $this->AddError("Error downloading data : $signedUrl : " . $error->getMessage()); return false; } } } private function MakeAndParseRequest($params,$itemPage,$lookup=false) { $this->item=0; /*$style=""; for($looper=1;$looper<=$totalPages;$looper++) { if($looper>($itemPage-3) && $looper<($itemPage+3)) { if($looper==$itemPage) { $style="style='color:red;'"; echo "".$looper."   "; } else { echo "".$looper."   "; } }else if($looper>($totalPages-3)) { echo "".$looper."   "; }else if($looper>(($totalPages/2)-3) && $looper<(($totalPages/2)+3)) { echo "".$looper."   "; } } */ } } ?>

提交回复
热议问题