本文介绍了使用R进行Amazon MWS API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R调用Amazon MWS API并收到以下错误:

I'm using R to make a call to the Amazon MWS API and get the following error:

帖子使用产品广告API帮了我很多.但是,我似乎无法使其在MWS方面正常工作.

This post helped me a lot with the Product Advertising API. However, I cannot seem to make it work on the MWS side.

这是我的代码:

library(digest)
library(RCurl)

base.html.string <- "https://mws.amazonservices.com/Products/2011-10-01?"

SellerID <- 'A2UZXXXXXXXXXX'
MWSAuthToken <- 'ATVPXXXXXXXXX'
MarketplaceID <- 'ATVPXXXXXXXXX'
AWSAccessKeyId <- 'AKIAXXXXXXXXXXXXXXXX'
AWSsecretkey <- 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 
ActionType <- 'GetMyPriceForASIN'
version.request = '2011-10-01'
ASINList.ASIN.1 <- 'B00XXXXXXX'

pb.txt <- Sys.time()

pb.date <- as.POSIXct(pb.txt, tz = Sys.timezone)

Timestamp = strtrim(format(pb.date, tz = "GMT", usetz = FALSE, "%Y-%m-%dT%H:%M:%SZ"), 24)

str = paste('POST\nmws.amazonservices.com\n/Products/2011-10-01\n',
            'ASINList.ASIN.1=', ASINList.ASIN.1,
            '&AWSAccessKeyId=', AWSAccessKeyId,
            '&Action=', ActionType,
            '&MWSAuthToken=', MWSAuthToken,
            '&MarketplaceId=', MarketplaceID,
            '&SellerId=', SellerID,
            '&SignatureMethod=HmacSHA256',
            '&SignatureVersion=2',
            '&Timestamp=', gsub('%2E','.',gsub('%2D', '-', curlEscape(Timestamp))),
            '&Version=', version.request,
            sep = '')

## signature test
Signature = curlEscape(base64(hmac(enc2utf8(AWSsecretkey), enc2utf8(str), algo = 'sha256', serialize = FALSE,  raw = TRUE)))


AmazonURL <- paste(base.html.string,
                   'ASINList.ASIN.1=', ASINList.ASIN.1,
                   '&AWSAccessKeyId=', AWSAccessKeyId,
                   '&Action=', ActionType,
                   '&MWSAuthToken=', MWSAuthToken,
                   '&MarketplaceId=', MarketplaceID,
                   '&SellerId=', SellerID,
                   '&SignatureMethod=HmacSHA256',
                   '&SignatureVersion=2',
                   '&Timestamp=', Timestamp,
                   '&Version=', version.request,
                   '&Signature=', Signature,
                   sep = '')

AmazonResult <- getURL(AmazonURL)

我正在使用Amazon MWS Scratchpad,并确保我要签名的字符串匹配.

I'm using the Amazon MWS Scratchpad and made sure my string to sign matches.

我的密钥确实包含+,但是我认为可以解决此问题.

My secret key does contain +'s, but I thought encoding would fix that.

任何帮助将不胜感激!

推荐答案

阅读此.我从字面上拿了Amazon的示例,并使用POST而不是GET.我还不必要地调整了我的时间戳计算,该问题也已修复.希望这可以帮助某人.

I figured out my problem after reading this post. I took Amazon's examples literally and used a POST instead of GET. I also had tweaked unnecessarily with my time stamp calculation, which I fixed as well. Hope this helps someone down the road.

这篇关于使用R进行Amazon MWS API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:56