This post is obsolete. See the updated post.

Since AVH Amazon plugin no longer works, as Amazon in its infinite wisdom removed the ListLookup API call, I had to create my own. Without an API, I resorted to a hacker's best friend: screen scraping. The wishlist page has a simple structure, and all links to Amazon products have as part of the URL "dp/{ASIN}", where {ASIN} is the Amazon ID number. If you view a wishlist in compact form, then the only links are to wishlist items and all the items (as far as I can tell) will be on a single page. Other advertisements for Amazon products that you see on the page are added with Javascript, so they won't show up when we grab the page with PHP.

So it's easy to get a list of ASIN's of the products on my wishlist:

function wishlist($listname){
	$url = "http://www.amazon.com/registry/wishlist/$listname?layout=compact";
	$contents = file_get_contents($url);
	preg_match_all ('|/dp/(\w+)/|', $contents, $ASINs, PREG_PATTERN_ORDER);
	return $ASINs[1]; // just get the numbers
}

This returns an array of ASIN's, that you can now pass the the Amazon ItemLookup API, which still works fine (Ulrich Mierendorff's AWS Signed Query makes that easy).

If your web hosting service disables file_get_contents, as mine does, you can use cURL instead.

As you can see from my sidebar, it seems to work well. Obviously, Amazon can change the layout and content of their pages without notice, but as we have seen, they can change the API as well.

11 Comments

  1. Fredyy says:

    Thank you, this really helped me out, i was searching for an alternative since they blocked ListLookUp

  2. Lior says:

    Hi,

    Look great.. only – what do you use for list name?

  3. Danny says:

    @Lior:
    The permalink to your wishlist is something like http://www.amazon.com/gp/registry/wishlist/1PUA0GNXIWGBK or shortened to http://amzn.com/w/1PUA0GNXIWGBK.
    The list ID is the alphanumeric stuff at the end. Unfortunately, Amazon doesn’t show that automatically anymore when you look at your wishlist, but you can see it if you click on “Share With Friends”, or when you search for a wishlist (it returns a URL that ends with ?...&id=1PUA0GNXIWGBK.
    You could also go back to screen scraping and search the source of your wishlist page for /\/wishlist\/(\w+)\// (that’s “/wishlist/listID/“).
    Amazon doesn’t have an API for looking up ID’s, but if you request the URL
    http://www.amazon.com/gp/registry/search.html?type=wishlist&field-name=d.wachss@prodigy.net
    it will return the URL
    http://www.amazon.com/gp/registry/registry.html?ie=UTF8&type=wishlist&id=1PUA0GNXIWGBK, so you could probably create your own look up function.
    Hope this helps (and feel free to use the above list ID to buy me a present!)
    –Danny

  4. Danny says:

    @Lior:
    OK, that intrigued me enough to write a quick PHP routine to find a wishlist based on the email address (only works if the person has only one wishlist):

    function wishlistid($email){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "http://www.amazon.com/gp/registry/search.html?type=wishlist&field-name=$email");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HEADER, true);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
      preg_match('/type=wishlist&id=(\w+)/', curl_exec($ch), $match);
      curl_close($ch);
      return $match[1];
    }
  5. Mauro Asprea says:

    You can also get the RSS feed of your Amazon Wish List using the service I built for such purpose: Wish and BAM http://www.wishandbam.com/

    Then you can parse the RSS with the php DOM library

    Please let me know if this works for you guys!

  6. Danny says:

    @Marco Asprea:
    How are you grabbing the wishlist information without the Amazon API?
    –Danny

  7. Mauro Asprea says:

    @Danny the same way google knows about the internet: Crawling ;)

    Let me know if you want some early access to try things out. I am building a simple interface for devs to generate a RSS feed given a Wish List URL. follow me on Twitter @wishandbam or @brutuscat and let me know ;)

  8. Danny says:

    @Marco
    Ah, so you’re looking at the HTML pages as well. I hoped you had some secret access to the API that would be easier.
    Danny

  9. Mauro Asprea says:

    Last week I wrote How to get an RSS feed out of my Amazon Wish List? http://getsatisfaction.com/wishandbam/topics/how_to_get_an_rss_feed_out_of_my_amazon_wish_list

    This way u can use your Amazon Wish List with your RSS Plugins/Widgets

  10. Danny says:

    @Mauro:
    The twitter trick looks cool. I don’t have a twitter account (it’s blocked at work and I hardly have time to look at the computer otherwise) but it may be worth it to play with the wishlist feed.
    –Danny

  11. Searching your Amazon.com Wish List « Code In Chinese says:

    […] recently removed wish list querying methods from their API. Bummer. Then I came upon this post. http://bililite.nfshost.com/blog/2010/10/31/hacking-my-way-to-an-amazon-wishlist-widget/ . The solution is the layout=compact URL […]

Leave a Reply


Warning: Undefined variable $user_ID in /home/public/blog/wp-content/themes/evanescence/comments.php on line 75