Ruby returns 中的亚马逊销售合作伙伴 API MissingAuthenticationToken

Amazon Selling Partner API in Ruby returns MissingAuthenticationToken

我一直在尝试使用 Ruby gem amz_sp_api

访问新的 Amazon 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

然后我进入 return

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[=11 将客户端传递给 api =]