ruby - Ruby 中的 Amazon Selling Partner API 返回 MissingAuthenticationToken
问题描述
我一直在尝试使用 Ruby gem 访问新的 Amazon SP-APIamz_sp_api
我已按照有关创建 IAM 用户以及获取我认为正确的令牌的所有说明进行操作。但我继续收到以下错误:
"message": "Access to requested resource is denied.",
"code": "MissingAuthenticationToken"
这是我正在使用的代码:
require 'amz_sp_api'
require 'product-pricing-api-model'
require 'fulfillment-outbound-api-model'
require 'byebug'
require 'aws-sdk-core'
AmzSpApi.configure do |config|
config.refresh_token = 'long string'
config.client_id = 'amzn1.application-oa2-client.123'
config.client_secret = 'secret'
config.credentials_provider = Aws::STS::Client.new(
region: AmzSpApi::SpConfiguration::AWS_REGION_MAP['na'],
access_key_id: 'key',
secret_access_key: 'secret_key'
).assume_role(role_arn: 'arn:aws:iam::123:role/SellerAPIRole', role_session_name: SecureRandom.uuid)
config.timeout = 20 # seconds
config.debugging = true
end
api_instance = AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new
marketplace_id = 'ATVPDKIKX0DER'
begin
result = api_instance.get_features(marketplace_id)
pp result
rescue AmzSpApi::FulfillmentOutboundApiModel::ApiError => e
puts "Exception when calling FbaOutboundApi->get_features: #{e}"
end
我得到回报
Exception when calling FbaOutboundApi->get_features: Error message: the server returns an error
HTTP status code: 403
Response headers: {"Date"=>"Wed, 12 May 2021 19:23:39 GMT", "Content-Type"=>"application/json", "Content-Length"=>"135", "Connection"=>"keep-alive", "x-amzn-RequestId"=>"123", "x-amzn-ErrorType"=>"MissingAuthenticationTokenException", "x-amz-apigw-id"=>"something"}
Response body: {
"errors": [
{
"message": "Access to requested resource is denied.",
"code": "MissingAuthenticationToken"
}
]
}
还有人看到这个问题吗?我经历了设置 IAM 用户和所有这些混乱的广泛的入职流程。
解决方案
这是因为您需要像这样 AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new(AmzSpApi::SpApiClient.new) 按照https://github.com/ericcj/amz_sp_api#getting-started将客户端传递给 API
推荐阅读
- fancybox-3 - 在不同的视口宽度上显示不同的图像
- r - 如何使用 Sys.Date() 或 today() 将日期重新编码为 R 中的字符串或因子?
- r - Why the output is not ordered by alphabetical way when I use factor() without setting levels?
- python - Finding the next value corresponding to a criteria
- c# - Using a dictionary to perform basic CRUD operations and getting an sqlite syntax error
- python - How to make Plotly average out observations at a single x-value Python
- python - Subtract each column by the preceding column on Dataframe in Python
- azure - Adding a ADF permissions to key vault in ARM
- javascript - Compare sheet 1 to sheet 2 and output to sheet 3. Google sheets. JavaScript
- python - python: rows from a textfile