Originally published on: 10/13/2006 7:11:35 PM
The first thing to do is get a quick handle on all of your wishlists that Amazon has on file. The scratchpad for the ListSearch gives a handy way to build the URL. Set the ListType to WishList and the rest is fairly straightforward. Include the email and the subscription ID (get yours at http://aws.amazon.com).
I gave it my email address and got my URL, which I then ran through the following code.
$xml = simplexml_load_file($url);
$lists = $xml->Lists;
foreach($lists->List as $list){
$ListURL = $list->ListURL;
$ListName = $list->ListName;
$TotalItems = $list->TotalItems;
$ListId = $list->ListId;
print("$ListName ($ListId) has $TotalItems items<br />");
}
That's useful if you want to find lists, for example to find the lists of family members, etc. However, for the next bit, I only really needed the $ListId, but who knows, the above might be useful and it got me the bit I needed.
So, we can do something very similar to get the URL to retrieve a list. The scratchpad for ListLookup gets the URL we need.
Again, using thhe SimpleXML functions is the quickest way to grab the data. Load your URL into a variable (it's a really long URL, so I'm not posting it to avoid messing the layout up). Anyway, when you run:
$xml = simplexml_load_file($url);
You have this object that represents what's in the XML. As such, it pretty much varies based on the XML you load. The easiest way to see what's inside is to do a print_r($xml) and you'll see a nicely nested object in the view source. Using the <pre> tag can make looking at the output easier.
In the case of a ListLookup, using this lookup gives you the actual details of the list:
$list = $xml->Lists->List;
Another quick print_r($list) and we can see that we're getting to the meat of what we're after. Depending on what properties you selected to build your URL, you may or may not have all of these, but for books and reasonable options, this little snippet:
$xml = simplexml_load_file($url);
$list = $xml->Lists->List;
foreach($list->ListItem as $item){
$detailURL = $item->Item->DetailPageURL;
$title = $item->Item->ItemAttributes->Title;
$author = $item->Item->ItemAttributes->Author;
print("$title by $author<br>");
}
Which generates a nice little list like this:
Stumbling on Happiness by Daniel Gilbert
The Long Tail: Why the Future of Business Is Selling Less of More by Chris Anderson
The Wisdom of Crowds by James Surowiecki
The Paradox of Choice: Why More Is Less (P.S.) by Barry Schwartz
Blink: The Power of Thinking Without Thinking by Malcolm Gladwell
If you did much digging through the object that you get from Amazon, you saw just how much data there is, which would make for whatever kinds of customized pages you want.