5

我是使用亚马逊产品广告 API 的新手,对于我的第一个项目,我正在尝试根据艺术家和标题获取特定歌曲的 MP3 下载产品的 ASIN。我最终将使用这些 ASIN 来填充Amazon MP3 Clips Widget

我正在使用CodeDiesel.com 的 PHP 类开始。它工作得很好,我添加了以下功能:

    public function searchMusic($artist, $title) {
        $parameters = array("Operation"     => "ItemSearch",
                            "Artist"        => $artist,
                            "Title"         => $title,
                            "SearchIndex"   => "Music",
                            "ResponseGroup" => "Medium");
        $xml_response=$this->queryAmazon($parameters);
        return $xml_response;
    }

现在,问题是,我似乎只能通过这种方式获得专辑。例如,如果我为艺术家输入“Robert Randolph”,为标题输入“Colorblind”,我会得到 Robert Randolph and the Family Band 的 Colorblind 专辑。如果我搜索特定曲目,例如“Thrill Of It”,亚马逊找不到任何内容。

所以我需要做的是首先弄清楚如何查询曲目标题。然后我需要弄清楚如何将我的结果限制为仅下载 MP3。我怎样才能做到这一点?

如果有关于该主题的文档,您能指出我正确的方向吗?我一直在阅读它,但没有看到任何我想要的参数。

感谢您的时间。

4

2 回答 2

9

文档的组织方式很奇怪,我自己也很难找到相关信息。

要查找 mp3,您必须将SearchIndex参数更改为“MP3Downloads”。然后,您必须使用“关键字”,而不是使用“艺术家”和“曲目”。将艺术家和曲目值组合成一个字符串作为“关键字”属性值。此外,尝试“MusicTracks” for SearchIndex,因为在那里您可能也会得到不同的结果。

这是我拥有的一个工作系统的一个片段,它执行类似类型的查找。

    $params = Array(
        "Operation"=>'ItemSearch',
        "SearchIndex"=>'MP3Downloads',
        "ResponseGroup"=>'ItemAttributes,Tracks,Images',
        "Keywords"=>$track['title'].' '.$artist['name']
    );
于 2011-02-16T18:31:58.533 回答
2

这也是我遇到的问题。我从同一个示例开始工作,我对它进行了大量修改并将其合并到我制作混搭的整个类集合中。我真正想要的是来自亚马逊的预览,给出艺术家和专辑标题。我会继续努力,现在我手上还有太多时间。我的混搭代码库在这里:

我的 Mashup 和代码库

我不断收到这个问题的推荐,我的解决方案与 Chris 的解决方案基本相同,我的代码中有两个方法/函数可以做到这一点:

        /**
     * Return the tracks found on an album, have to page to get them all which this method does not do.
     * 
     * @param string $albumTitle 
     * @param string $artist
     * @return mixed simpleXML object
     */
    public function getMP3sForAlbumByArtist($albumTitle, $artist)
    {
        $searchTerm = $albumTitle . ' ' . $artist;
        $parameters = array("Operation"   => "ItemSearch",
                            "Keywords"    => $searchTerm,
                            "SearchIndex" => AmazonProductAPI::CATEGORY_MP3_DOWNLOADS,
                            "ResponseGroup" => AmazonProductAPI::RESPONSE_GROUP_TRACKS);

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

        return $xml_response;
    }



    /**
     * Return the tracks found on a song title and artist
     * 
     * @param string $songTitle 
     * @param string $artist
     * @return mixed simpleXML object
     */
    public function getMP3ForSongByArtist($songTitle, $artist)
    {
        $searchTerm = $songTitle . ' ' . $artist;
        $parameters = array("Operation"   => "ItemSearch",
                            "Keywords"    => $searchTerm,
                            "SearchIndex" => AmazonProductAPI::CATEGORY_MP3_DOWNLOADS,
                            "ResponseGroup" => AmazonProductAPI::RESPONSE_GROUP_TRACKS);

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

        return $xml_response;
    }

我的代码可以从上面的链接下载或在 GitHub 中,它基于我更新的旧代码示例。它在我的主机上运行良好,但 iTunes 更适合预览歌曲。

于 2011-10-04T22:25:31.470 回答