我正在尝试使用GetMatchingProductForId操作从Amazon MWS API获取数据。当我使用Amazon MWS Scratchpad时,它工作得非常好。
我现在正在尝试复制在HTTP POST请求中发送的urls,但我收到了签名错误消息。
以下是Amazon MWS Scratchpad中请求的详细信息,我匿名了私有标识符,但这是我唯一更改的内容:
HTTP POST
POST /Products/2011-10-01?AWSAccessKeyId=ANONYMIZED
&Action=GetMatchingProductForId
&SellerId=ANONYMIZED
&SignatureVersion=2
&Timestamp=2018-09-28T05%3A45%3A43Z
&Version=2011-10-01
&Signature=ANONYMIZED
&SignatureMethod=HmacSHA256
&MarketplaceId=A13V1IB3VIYZZH
&IdType=EAN
&IdList.Id.1=9781933988665 HTTP/1.1
Host: mws.amazonservices.fr
x-amazon-user-agent: AmazonJavascriptScratchpad/1.0 (Language=Javascript)
Content-Type: text/xml要签名的字符串
POST
mws.amazonservices.fr
/Products/2011-10-01
AWSAccessKeyId=ANONYMIZED&Action=GetMatchingProductForId&IdList.Id.1=9781933988665&IdType=EAN&MarketplaceId=A13V1IB3VIYZZH&SellerId=ANONYMIZED&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2018-09-28T05%3A45%3A43Z&Version=2011-10-01=======
现在我的问题是,根据HTTP POST,请求应该是什么样子的(假设我的签名被正确创建)?这是我的尝试:
https://mws.amazonservices.fr/Products/2011-10-01?AWSAccessKeyId=ANONYMIZED&Action=GetMatchingProductForId&SellerId=ANONYMIZED&SignatureVersion=2&Timestamp=2018-09-28T05%3A52%3A33Z&Version=2011-10-01&Signature=ANONYMIZED&SignatureMethod=HmacSHA256&MarketplaceId=A13V1IB3VIYZZH&IdType=EAN&IdList.Id.1=9781933988665但是,便签簿中的'\n‘转义字符又如何呢?那么在结尾的'HTTP/1.1'呢,我应该把它也包括进来吗?
谢谢你的帮助。
发布于 2018-09-28 19:28:53
我没有MWS帐户,所以我不能测试以下内容,但这是你可以做到的一种方法:
# set this to your python2 binary; you'll need to do
# pip2 install boto
# from a command-line before using this code
Sys.setenv("RETICULATE_PYTHON"="/usr/bin/python2.7")
library(reticulate)
boto_mws_connection <- import("boto.mws.connection")
con <- boto_mws_connection$MWSConnection(
aws_access_key_id = ACCESS_KEY
aws_secret_access_key = AWS_SECRET
Merchant = MERCHANT_ID
)
con$get_matching_product_for_id(
MarketplaceId = "A13V1IB3VIYZZH",
IdType = "EAN",
IdList = c("9781933988665")
)发布于 2018-10-01 01:33:53
HTTP/1.1通常由您的http客户端库创建。我对R不熟悉,但我用谷歌搜索了一下,似乎有一个CURL package for R。CURL是包括PHP在内的许多语言的标准http库。我通过curl发送XML提要的PHP代码如下所示:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://mws.amazonservices.fr/Products/2011-10-01?.....your data and signature here...');
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlcontent);
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
"Content-Type: text/xml",
"Content-MD5: ".base64_encode(md5($xmlcontent,true)),
"x-amazon-user-agent: TestScript/0.01")
);
$result = curl_exec($ch);
curl_close($ch);通过查看this,在我看来,这应该很容易翻译成CURL的R接口。
https://stackoverflow.com/questions/52549385
复制相似问题