我有一个类似的问题,这是我解决它的方法:
首先,我打电话Amazon::Ecs.methods
看到有debug
, 和debug=
方法,Amazon::Ecs.debug
设置为false
很自然,我将其设置为 true Amazon::Ecs.debug = true
,然后尝试相同的搜索:
Amazon::Ecs.item_search('ruby')
# this time it gave the following output (secret keys masked by me)
irb(main):020:0> Amazon::Ecs.item_search('ruby')
Adding AWSAccessKeyId=*****************
Adding AssociateTag=*****************
Adding Keywords=ruby
Adding Operation=ItemSearch
Adding SearchIndex=Books
Adding Service=AWSECommerceService
Adding Timestamp=2015-11-13T20:25:04Z
Adding Version=2011-08-01
Request URL: http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=*****************&AssociateTag=*****************&Keywords=ruby&Operation=ItemSearch&SearchIndex=Books&Service=AWSECommerceService&Timestamp=2015-11-13T20%3A25%3A04Z&Version=2011-08-01&Signature=****************************%3D
Amazon::RequestError: HTTP Response: 400 Bad Request
from /Users/`whoami`/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/amazon-ecs-2.3.1/lib/amazon/ecs.rb:132:in `send_request'
from /Users/`whoami`/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/amazon-ecs-2.3.1/lib/amazon/ecs.rb:101:in `item_search'
from (irb):20
from /Users/`whoami`/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'
然后,我将 URL 复制/粘贴到浏览器中,浏览器给出如下 XML 响应:
<ItemLookupErrorResponse xmlns="http://ecs.amazonaws.com/doc/2011-08-01/">
<Error>
<Code>AWS.InvalidAccount</Code>
<Message>
Your AccessKey Id is not registered for Product Advertising API. Please use the AccessKey Id obtained after registering at https://affiliate-program.amazon.com/gp/flex/advertising/api/sign-in.html
</Message>
</Error>
<RequestId>********-****-****-****-************</RequestId>
</ItemLookupErrorResponse>
但在我的特殊情况下,事实证明,我已经正确设置了所有内容,但是我最近刚刚创建了一个新的访问密钥,并且似乎需要几分钟才能接受我的新凭据。有趣的是,一旦我意识到可能是这种情况,并再次尝试,它就成功了!
编辑:如果不是很明显,答案在消息中:“您的 AccessKey Id 未注册产品广告 API。请使用在 https://affiliate-program.amazon.com/注册后获得的 AccessKey Id gp/flex/advertising/api/sign-in.html "