Amazon Product API with R

I would like to use R to send requests to the Amazon Product API.

Is there a way to authenticate and request an Amazon product API with R without getting the following error:

"The request signature we signed does not match the signature you provided. Verify your AWS secret access key and signature method. For more details, see the technical documentation."

+8
rest api r amazon-web-services amazon-product-api
source share
5 answers

try it

This should do a search using the product advertising API, which I think you have in mind.

You need to provide AWSAccessKeyId and AWSsecretkey,

which can be obtained at: http://docs.amazonwebservices.com/AWSECommerceService/2011-08-01/GSG/

search.amazon <- function(Keywords, SearchIndex = 'All', AWSAccessKeyId, AWSsecretkey, AssociateTag, ResponseGroup = 'Small', Operation = 'ItemSearch'){ library(digest) library(RCurl) base.html.string <- "http://ecs.amazonaws.com/onca/xml?" SearchIndex <- match.arg(SearchIndex, c('All', 'Apparel', 'Appliances', 'ArtsAndCrafts', 'Automotive', 'Baby', 'Beauty', 'Blended', 'Books', 'Classical', 'DigitalMusic', 'DVD', 'Electronics', 'ForeignBooks', 'Garden', 'GourmetFood', 'Grocery', 'HealthPersonalCare', 'Hobbies', 'HomeGarden', 'HomeImprovement', 'Industrial', 'Jewelry', 'KindleStore', 'Kitchen', 'Lighting', 'Magazines', 'Marketplace', 'Miscellaneous', 'MobileApps', 'MP3Downloads', 'Music', 'MusicalInstruments', 'MusicTracks', 'OfficeProducts', 'OutdoorLiving', 'Outlet', 'PCHardware', 'PetSupplies', 'Photo', 'Shoes', 'Software', 'SoftwareVideoGames', 'SportingGoods', 'Tools', 'Toys', 'UnboxVideo', 'VHS', 'Video', 'VideoGames', 'Watches', 'Wireless', 'WirelessAccessories')) Operation <- match.arg(Operation, c('ItemSearch', 'ItemLookup', 'BrowseNodeLookup', 'CartAdd', 'CartClear', 'CartCreate', 'CartGet', 'CartModify', 'SimilarityLookup')) ResponseGroup <- match.arg(ResponseGroup, c('Accessories', 'AlternateVersions', 'BrowseNodeInfo', 'BrowseNodes', 'Cart', 'CartNewReleases', 'CartTopSellers', 'CartSimilarities', 'Collections', 'EditorialReview', 'Images', 'ItemAttributes', 'ItemIds', 'Large', 'Medium', 'MostGifted', 'MostWishedFor', 'NewReleases', 'OfferFull', 'OfferListings', 'Offers', 'OfferSummary', 'PromotionSummary', 'RelatedItems', 'Request', 'Reviews', 'SalesRank', 'SearchBins', 'Similarities', 'Small', 'TopSellers', 'Tracks', 'Variations', 'VariationImages', 'VariationMatrix', 'VariationOffers', 'VariationSummary'), several.ok = TRUE) version.request = '2011-08-01' Service = 'AWSECommerceService' if(!is.character(AWSsecretkey)){ message('The AWSsecretkey should be entered as a character vect, ie be qouted') } pb.txt <- Sys.time() pb.date <- as.POSIXct(pb.txt, tz = Sys.timezone) Timestamp = strtrim(format(pb.date, tz = "GMT", usetz = TRUE, "%Y-%m-%dT%H:%M:%S.000Z"), 24) str = paste('GET\necs.amazonaws.com\n/onca/xml\n', 'AWSAccessKeyId=', curlEscape(AWSAccessKeyId), '&AssociateTag=', AssociateTag, '&Keywords=', curlEscape(Keywords), '&Operation=', curlEscape(Operation), '&ResponseGroup=', curlEscape(ResponseGroup), '&SearchIndex=', curlEscape(SearchIndex), '&Service=AWSECommerceService', '&Timestamp=', gsub('%2E','.',gsub('%2D', '-', curlEscape(Timestamp))), '&Version=', version.request, sep = '') ## signature test Signature = curlEscape(base64(hmac( enc2utf8((AWSsecretkey)), enc2utf8(str1), algo = 'sha256', serialize = FALSE, raw = TRUE))) AmazonURL <- paste(base.html.string, 'AWSAccessKeyId=', AWSAccessKeyId, '&AssociateTag=', AssociateTag, '&Keywords=', Keywords, '&Operation=',Operation, '&ResponseGroup=',ResponseGroup, '&SearchIndex=', SearchIndex, '&Service=AWSECommerceService', '&Timestamp=', Timestamp, '&Version=', version.request, '&Signature=', Signature sep = '') AmazonResult <- getURL(AmazonURL) return(AmazonResult) } 

The URL that we get from running this code will not give the signature address. To get the signature address, use the following web address and paste the URL there and click "Display Signed URL".

http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html

+8
source share

See this post , as well as the Amazon Signed Query Assistant . This post, along with the two links I shared, helped me get started with the Amazon Product Advertising API.

+1
source share

I am new and I don’t have enough β€œrep” for comments, but in response to Micha there should be a comma after Signature in this area (I added a comma):

 AmazonURL <- paste(base.html.string, 'AWSAccessKeyId=', AWSAccessKeyId, '&AssociateTag=', AssociateTag, '&Keywords=', Keywords, '&Operation=',Operation, '&ResponseGroup=',ResponseGroup, '&SearchIndex=', SearchIndex, '&Service=AWSECommerceService', '&Timestamp=', Timestamp, '&Version=', version.request, '&Signature=', Signature, sep = '') 
+1
source share

Check out http://www.omegahat.org/ . There are several packages related to Amazon, and even if the Product API may not be among them, you should be able to copy the main features.

0
source share

who is interested in the Amazon API?

I have never seen an interface for the "Product Advertising API"! For AWS, you can use the AWS package toolkit in CRAN: http://cran.r-project.org/web/packages/AWS.tools/index.html

-one
source share

All Articles