使用R进行Amazon MWS API调用 [英] Using R to make Amazon MWS API calls

查看:98
本文介绍了使用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:

我们计算出的请求签名与您的签名不匹配 假如.检查您的AWS Secret Access密钥和签名方法.咨询 服务文档以了解详细信息.

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

帖子使用产品广告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.

任何帮助将不胜感激!

推荐答案

阅读此

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调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆