使用Rails 4 Vacuum gem在Amazon Product Api中获取RelatedItems

时间:2016-02-03 08:16:04

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

我正在我的rails应用程序中集成Amazon Product Api。现在唯一剩下的就是在执行item_lookup操作时获取相关项列表。

当我在ResponseGroup中添加RelatedItems时,如下所示:

    response = request.item_lookup(
    query: {
        'ItemId' => params[:id],
        'ResponseGroup' => "ItemAttributes,Images,Reviews,RelatedItems"
    }
    )

我收到此错误:

"Errors"=>{"Error"=>{"Code"=>"AWS.MissingParameterValueCombination", "Message"=>"Your request is missing a required parameter combination.  When ResponseGroup equals RelatedItems, RelationshipType must be present."}}}

我似乎需要在查询中添加RelationshipType

问题是我的类别被保存在后端。 search_indexkeyword被传递到item_search操作,在那里我获取ASIN,我将其作为参数传递给item_lookup操作。问题是如何在此处添加 RelationshipType ,并且根据所显示的产品,它必须是动态的。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以简单地将所有现有的RelationshipType值添加到ItemLookup请求中。 RelationshiptType集限制为15个有效值,因此您可以将所有这些值包含在请求中,如下所示:

response = request.item_lookup(
query: {
    'ItemId' => params[:id],
    'ResponseGroup' => "ItemAttributes,Images,Reviews,RelatedItems"
    ...
    'RelationshipType' => "Tracks,DigitalMusicArranger,DigitalMusicComposer,DigitalMusicConductor,DigitalMusicEnsemble,DigitalMusicLyricist,DigitalMusicPerformer,DigitalMusicPrimaryArtist,DigitalMusicProducer,DigitalMusicRemixer,DigitalMusicSongWriter,Episode,Season"
}
)