亚马逊产品API与R
我想使用R将请求发送到Amazon产品API服务。
有没有一种方法来验证和查询亚马逊产品API与R没有得到以下错误:
“我们计算的请求签名与您提供的签名不匹配,请检查您的AWS秘密访问密钥和签名方法,详情请参阅服务文档。
尝试这个
这应该使用产品广告API执行搜索,我认为您的意思是。
您需要提供AWSAccessKeyId和AWSsecretkey,
可以通过以下网址获取: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('GETnecs.amazonaws.comn/onca/xmln',
'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)
}
我们从运行此代码获得的URL不会给出签名地址。 要获得签名地址,请使用以下网址并将URL粘贴到那里,然后单击显示签名的URL。
http://associates-amazon.s3.amazonaws.com/signed-requests/helper/index.html
看到这篇文章以及Amazon的Signed Requests Helper。 这篇文章以及我共享的两个链接帮助我启动并运行了亚马逊的产品广告API。
我是新的,我没有足够的“代表”发表评论,但在Micha的回答中,在此领域的Signature之后需要逗号(我已添加逗号):
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 = '')
链接地址: http://www.djcxy.com/p/38985.html