【问题标题】:fetch ItemId in Amazon Product Api using Rails Vacuum gem使用 Rails Vacuum gem 在 Amazon Product Api 中获取 ItemId
【发布时间】:2016-05-08 18:41:09
【问题描述】:

我正在将 Amazon Product Api 集成到我的 rails 应用程序中。我正在使用真空宝石进行这种集成。有两个主要页面。我正在通过此代码获取产品。

    requestd = Vacuum.new

    requestd.configure(
    aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    associate_tag: ENV['ASSOCIATE_TAG']
    )

    response = requestd.item_search(
    query: {
        'SearchIndex' => @category.search_index,
        'Keywords' => @category.keyword,
        'ResponseGroup' => "ItemAttributes,Images"
    }
    )

    hashed_products = response.to_h

    @products = []

    hashed_products['ItemSearchResponse']['Items']['Item'].each do |item|
      product = OpenStruct.new
      product.name = item['ItemAttributes']['Title']
      product.price = item['ItemAttributes']['ListPrice']['FormattedPrice'] if item['ItemAttributes']['ListPrice']
      product.url = item['DetailPageURL']
      product.feature = item['ItemAttributes']['Feature']
      product.image_url = item['LargeImage']['URL'] if item['LargeImage']
      product.link = item['ItemLinks']['ItemLink'][5]['URL']
      @products << product
    end

它给出了十个具有匹配请求的产品。但是,当我想在我的应用程序中转到产品的详细信息页面并在我的应用程序中显示其各自的详细信息时,我需要 vaccum 文档中给出的该产品的 ItemId。

response = request.item_lookup(
  query: {
    'ItemId' => '0679753354'
  }
)

但我无法获取此 ID。当我在响应组中写 ItemIdItemIds 时,我没有得到这一点,尽管这是可以根据 Amazon Docs 写入 ResponseGroup 的属性。我需要该 ItemId 来执行项目循环操作,以便分别获得与该产品相关的评论和其他详细信息。

【问题讨论】:

  • 能否用您从 ItemSearch 操作获得的响应(以 XML 或 JSON 或任何其他形式)更新您的问题?如果您收到了包含 10 件商品的回复,则每件商品都应包含其 ID(称为“ASIN”的属性)。

标签: ruby-on-rails ruby amazon-web-services amazon-product-api vacuum


【解决方案1】:

我不熟悉 Ruby,但每种编程语言的方法都应该相同。 您要查找的 ItemId 属性称为 ASIN,您应该可以通过以下方式获取它:

product.asin = item['ASIN']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多