Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LXF 151 Perl project

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Magazine and coverdiscs
View previous topic :: View next topic  
Author Message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Tue Oct 25, 2011 11:09 pm    Post subject: LXF 151 Perl project Reply with quote

I've followed the steps in the tutorial as far as trying out the book add command but all I get is:

robert@milo:~/programming/perl$ ./book add 0330258648
Error: Forbidden

I take this to mean that Amazon has refused the request. Has anyone got this to work?
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Wed Oct 26, 2011 12:09 pm    Post subject: Reply with quote

I've had a look at the Net::Amazon documentation at Sourceforge and added some debugging. book seems to be doing what it should:

robert@milo:~/programming/perl$ ./book add 9781847394651
2011/10/26 11:39:40 request: params = $VAR1 = {
'ItemId' => '9781847394651',
'ResponseGroup' => 'Large',
'locale' => 'uk',
'Sort' => 'salesrank',
'ItemPage' => 1,
'Operation' => 'ItemLookup'
};

2011/10/26 11:39:40 urlstr=http://webservices.amazon.co.uk/onca/xml?AWSAccessKeyId=%2Fhome%2FrobertDesktopDownloadsrsa-APKAJKF7VYMOH27RN43Q.pem&ItemId=9781847394651&ItemPage=1&Operation=ItemLookup&ResponseGroup=Large&Service=AWSECommerceService&Sort=salesrank&Timestamp=2011-10-26T10%3A39%3A40Z&Version=2009-07-01&locale=uk&Signature=230gYjcrrPmY7FC4G3OzWnXRSRaDdD2g4iG2HPiDqNQ%3D
2011/10/26 11:39:40 Fetching http://webservices.amazon.co.uk/onca/xml?AWSAccessKeyId=%2Fhome%2FrobertDesktopDownloadsrsa-APKAJKF7VYMOH27RN43Q.pem&ItemId=9781847394651&ItemPage=1&Operation=ItemLookup&ResponseGroup=Large&Service=AWSECommerceService&Sort=salesrank&Timestamp=2011-10-26T10%3A39%3A40Z&Version=2009-07-01&locale=uk&Signature=230gYjcrrPmY7FC4G3OzWnXRSRaDdD2g4iG2HPiDqNQ%3D
Error: Forbidden

The key is the one I downloaded from Amazon Web Services, is it, prthaps the wrong one?
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Thu Oct 27, 2011 2:16 pm    Post subject: Reply with quote

I've done some digging around the Amazon Product Advertising API website and have discovered that I was sending the wrong identification.

The AMAZON_KEY variable needs to be your Access Key ID, in my case AKIAJEW2TL6RBGT65SXA, not the filename of your public key but we then hit another snag:

robert@milo:~/programming/perl$ ./book add 0750632445
Error:Your request is missing required parameters. Required parameters include AssociateTag.

There is no mention of an Associate tag in the article or in the code on the DVD, I suspect that Amazon have changed the rules since the article was written.
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Tue Nov 01, 2011 12:08 am    Post subject: Reply with quote

I've just updated my system and It looks like Net::Amazon has been updated to include the associate tag feature:

robert@milo:~/programming/perl$ ./book add 0330258648
Mandatory paramter 'associate_tag' not defined at /usr/local/share/perl/5.10.1/Net/Amazon.pm line 67.

Didn't get that error last week.
Back to top
View user's profile Send private message
davorg



Joined: Wed May 25, 2005 1:12 pm
Posts: 2

PostPosted: Wed Nov 09, 2011 2:57 pm    Post subject: Reply with quote

Hi,

I saw this error when I returned to the project to start work on the next article in the series last week.

Amazon have changed the way that the API authentication works. Now you need to include the associate tag in your requests. Net::Amazon will do that for you if you add it to your call to 'new'.

Code:
my $az = Net::Amazon->new(
  token         => $ENV{AMAZON_KEY},
  secret_key    => $ENV{AMAZON_SECRET},
  associate_tag => $ENV{AMAZON_ASST_TAG},
  locale        => 'uk',
);


It's unfortunate that the changed it in the middle of this series. The really annoying thing is that the second article in the series has already been submitted with the same out of date information. It'll only be in the third article (which won't be published until next year) that I'll be able to include a correction.

Sorry about that,

Dave...
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Tue Nov 15, 2011 7:35 pm    Post subject: Reply with quote

Got this working at last, got my Associate Tag (even though my web site only has an 'under construction' page), worked out that the AMAZON_SECRET variable needs to be the string which appears when you click the link next to your Access Key ID at https://aws-portal.amazon.com/gp/aws/developer/account/index.html?ie=UTF8&action=access-key.

The only issue I've now got is over ISBN numbers:

robert@milo:~/programming/perl$ ./book list
Reading:


To Read:

* Learning Perl (Randal L. Schwartz)
* Heartstone (Matthew Shardlake 5) (C. J. Sansom)

Read:

Learning Perl went in just like that, using the 10-digit ISBN number from the book itself (entered as a single 10-digit string, no dashes) but the 13-digit ISBN from Heartstone wasn't recognised and I had to get the 10-digit ISBN from Amazon's website in order to get it added.
Back to top
View user's profile Send private message
davorg



Joined: Wed May 25, 2005 1:12 pm
Posts: 2

PostPosted: Tue Nov 15, 2011 8:04 pm    Post subject: Reply with quote

Yeah, it's not really the ISBN. It's actually the Amazon ASIN. That's the ten-character version of the ISBN for books.
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Tue Nov 15, 2011 11:17 pm    Post subject: Reply with quote

I've been looking at the Wikipedia page on ISBN's which says that 13 digit ISBN numbers are made up of a 3-digit country prefix (more or less), a 9-digit reference number and a check digit; it gives the formula for calculating the check digit so I'll nock up a script to convert a 13-digit ISBN to a 10-digit ISBN in the next couple of days.
Back to top
View user's profile Send private message
systemaddict



Joined: Tue Oct 25, 2011 10:58 pm
Posts: 9
Location: Edgware, Middlesex

PostPosted: Wed Nov 16, 2011 8:02 pm    Post subject: Reply with quote

Here's my script:


#!/usr/bin/perl -w
#
# isbn_convertor - a tool to derive a pre-2007 10-digit ISBN
# number from a post-2007 13-digit ISBN number.
#
# The first three digits of the ISBN-13 number can be discarded
# but the last digit is a check digit computed from the
# rest of the number and this has to be re-calculated . . .
#
print "Give us the 13 digits, no spaces or dashes: ";
$isbn13 = <STDIN>;
chomp($isbn13);
#
# create a 13-element array from the input string:
#
@isbn13 = split(//, $isbn13);
#
# calculation of the check digit is explained at
# http://en.wikipedia.org/wiki/International_Standard_Book_Number
#
$multiplier = 10;
for ($i = 3; $i <12; $i++){
$what = $isbn13[$i];
$product = $what * $multiplier;
$sum += $product;
--$multiplier;
}
$mod = $sum % 11;
$check = 11 - $mod;
if ($check =~ 10){
$check = 'X';
}
@isbn10 = @isbn13[3..11];
push(@isbn10, $check);
$asin = join("",@isbn10);
print "Your ASIN is $asin\n";


I've tested it with 14 books, I got one anomaly where I mistyped the ISBN for The Suspicions of Mr Whicher and got the ASIN for a different book although other mistypes returned errors from Amazon, I guess the check digit isn't infallible.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Magazine and coverdiscs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast