質問

I need to use the Amazon Product API via perl to get a list of third party new and used (marketplace) offers given an ASIN. I need to be able to see prices and whether each offer is fulfilled by amazon (eligible for prime/super saver shipping). I've scoured the Net::Amazon module, and I don't see any way to do this.

Has anyone done anything similar?

役に立ちましたか?

解決

So I was looking in to this myself, and it looks like items offered by Amazon have the attribute 'IsEligibleForSuperSaverShipping' => '1' in the offers. So this would be something like:

my $ua = Net::Amazon->new(
    associate_tag => 'derpderp',
    token         => 'morederp',
    secret_key    => 'herpaderp',
);

my $rsp = $ua->search( asin => 'B000FN65ZG' );

if ($rsp->is_success()) {
    if (my $o = $rsp->{xmlref}->{Items}->{Offers}) {
        foreach my $offer (keys %{ $o }) {
            if ($o->{$offer}->{IsEligibleForSuperSaverShipping}) {
                # This is offered by Amazon.com
            } # if
        } # foreach
}
else {
    die "Error: ", $rsp->message(), "\n";
}
  • note, as of writing (04-Nov-13), that ASIN is fulfilled through Amazon; it may not be in the future.

The problem here is that Net::Amazon generates its accessors magically (and not using Class::Accessor, but it's old, so we can forgive it…). I am not sure what the correct accessor is for the individual offers within the {Items} element above. Reaching into your object is kind of fraught with peril, but in this case, finding the right accessor should not be so hard (given it is automagicaly generated) and barring that, I think you can feel comfortable reaching right into the object.

Also, you might suggest reaching out to the author's author, Mike Schilli, or current maintainer, Christopher Boumenot, might be worth doing, especially if this is something that's in the result from Amazon consistently and could just be added to the API. The problem with this is that the return from Amazon is kind of variable. Quoting the perldoc,

Methods vary, depending on the item returned from a query. Here's the most common ones. They're all accessors, meaning they can be used like Method() to retrieve the value or like Method($value) to set the value of the field.

This makes it tricky to assume that you can test the return for super-saver-shipping-ness because it may just not have that key in the structure returned.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top