开发者

Querying Amazon Product API to get ASIN of MP3 download using artist and title

I am new using Amazon's Product Advertising API, and for my first project with it, I am trying to get the ASIN of the MP3 download product of a particular song, based on the artist and title. I will eventually be using these ASINs to populate an Amazon MP3 Clips Widget.

I am using the PHP class from CodeDiesel.com to get started. It works just fine, and I have added the following function:

    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;
    }

Now, th开发者_如何学JAVAe trouble is, I can only seem to get albums this way. For instance, if I put in "Robert Randolph" for the artist, and "Colorblind" for the title, I get Robert Randolph and the Family Band's Colorblind album. If I search for a particular track, such as "Thrill Of It", Amazon can't find anything.

So what I need to do is first figure out how to make a query for track title. Then I need to figure out how to limit my results to just MP3 downloads. How can I do this?

If there is documentation on the topic, can you point me in the right direction? I have been reading through it, but don't see any parameters for what I want.

Thank you for your time.


The documentation is oddly organized, and I have a hard time finding relevant information myself.

To look up mp3s, you have to change your SearchIndex parameter to 'MP3Downloads'. Then, instead of using "Artist" and "Track", you have to use "Keywords". Combine the artist and track values into one string for the "Keywords" property value. Also, try "MusicTracks" for SearchIndex, as you might get different results there as well.

This is a snippet from a working system I have that does a similar type of lookup.

    $params = Array(
        "Operation"=>'ItemSearch',
        "SearchIndex"=>'MP3Downloads',
        "ResponseGroup"=>'ItemAttributes,Tracks,Images',
        "Keywords"=>$track['title'].' '.$artist['name']
    );


This was a problem I had as well. I worked from the same example which I heavily modified and incorporated into a whole collection of classes which I made mashups out of. What I really want is the previews from Amazon given an artist and album title. I'm going to keep working on it, now that I still have too much time on my hands. My mashup codebase is here:

My Mashup's and codebase

I keep getting referrals from this question, my solution is basically the same as Chris's, I have two methods/functions that do this in my code:

        /**
     * 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;
    }

My code is downloadable from the above link or is in GitHub, it is based on older code examples I've updated. It is running OK on my host, but iTunes is better for previews of songs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜