开发者

Amazon Product Advertising API: Get Product Detail URL from ASIN

I am using the PHP Soap Library to connect to Amazon and retrieve pr开发者_JAVA技巧oduct cover art from ASINs. That much I've accomplished, but according to the Agreement (at least as far as I can tell; IANAL), any info I get from the API must be linked to its respective Product Detail Page on the Amazon retail site. I've browsed through the docs, but for the life of me I can not figure out what method, etc. I need to use, short of constructing the URL manually (which is potentially unstable). Any insight?


Figured it out. This is the code I ended up using:

<?php
class AmazonMusicSearch extends AmazonECS {
    protected $asin;
    protected $detailPageUrl;
    protected $ecs;

    function __get($name) {
        return $this->$name;
    }

    function __construct() {
        $this->ecs = new parent(AZ_APP_ID, AZ_APP_SECRET, 'com', AZ_ASSOCIATE_TAG);
    }

    function searchByAsin($asin) {
        $search = $this->ecs->responseGroup('Small')->category('Music')->search($asin);

        $this->asin = $asin;

        if(isset($search['Items']['Item']['DetailPageURL'])) {
            $this->detailPageUrl = $search['Items']['Item']['DetailPageURL'];
        } elseif(isset($search['Items']['Item'][0]['DetailPageURL'])) {
            $this->detailPageUrl = $search['Items']['Item'][0]['DetailPageURL'];
        } else {
            return false;
        }

        return $this;
    }

    function detailPageFromAsin($asin) {
        return $this->searchByAsin($asin)->detailPageUrl;
    }
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜