Hack 43 Gather Your Friends' Amazon IDs

figs/expert.giffigs/hack43.gif

Linking directly to someone's community activities requires finding their Amazon ID.

Each community user at Amazon is identified with an Amazon ID, an alphanumeric string that represents an Amazon account. The URLs of the community features revolve around these IDs, and to link directly to certain features (and to use some of the hacks in this book!) you'll need to know your own Amazon ID.

Your Amazon ID can be found in almost every community feature URL. Start out at the Friends & Favorites page, http://amazon.com/exec/obidos/subst/community/community-home.html. On the lefthand side of the page, click "Your About You Area" and note the URL. The string after member-glance is your Amazon ID.

http://www.amazon.com/exec/obidos/tg/cm/member-glance/-/Amazon ID

43.1 Linking Directly to Community Features

Now that you know your ID, you can link directly to any of your community-related activities:

About You Area

Your Amazon home page that includes a summary of all your community activities, and links to other community areas.

http://amazon.com/exec/obidos/tg/cm/member-glance /-/Amazon ID /
Favorite People

A list of people you've added to your Friends list.

http://amazon.com/exec/obidos/tg/cm/member-favorites /-/Amazon ID /
Reviews

A list of all the reviews you've contributed to Amazon.

http://amazon.com/exec/obidos/tg/cm/member-reviews /-/Amazon ID /
Lists

A list of all the Listmania! lists you've published.

http://amazon.com/exec/obidos/tg/cm/member-fil /-/Amazon ID /
Guides

A list of the guides you've created.

http://amazon.com/exec/obidos/tg/cm/member-guides /-/Amazon ID /

Linking to your activities is a bit narcissistic, so it'd be nice to have your friends' Amazon IDs to speed up the community deep linking. You know how to access your Favorite People page, and collecting their IDs is a snap with screen scraping.

43.2 The Code

This Perl script, get_friend_IDs.pl, uses an Amazon ID, grabs the HTML of the Friends list, and finds your friends' Amazon IDs.

#!/usr/bin/perl
# get_friend_IDs.pl
# A script to scrape Amazon, retrieve friend IDs, and write to a file
# Usage: perl get_friend_IDs.pl <amazonID>

#Take the asin from the command-line
my $amazonID =shift @ARGV or die "Usage:get_friend_IDs.pl <amazonID>\n";

#Assemble the URL
my $url = "http://amazon.com/exec/obidos/tg/cm/member-favorites/-/" .
          $amazonID . "/";

use strict;
use LWP::Simple;

#Request the URL
my $content = get($url);
die "Could not retrieve $url" unless $content;

my $friends = (join '', $content);

while ($friends =~ m!<b><a href="/exec/obidos/tg/cm/member-glance/-/(.*?)/[RETURN]
ref=cm_aya_av.fp_faya/">(.*?)</a></b>!mgis) {
    my($amznID,$name) = ($1||'',$2||'');
    #Print the results
    print $name . " (" . 
          $amznID . ")" .
          "\n\n";
}

43.3 Running the Hack

Run this code from a command line, passing it your Amazon ID:

perl get_friend_IDs.pl Amazon ID

The script will return all of the users on the Friends page, along with their Amazon IDs in parentheses:

User Name (Amazon ID)