c# - 亚马逊产品广告 API - 搜索多个 UPC

标签 c# amazon-web-services

我正在使用亚马逊产品广告 API 搜索 2 个不同的 UPC:

 // prepare the first ItemSearchRequest
 // prepare a second ItemSearchRequest
 ItemSearchRequest request1 = new ItemSearchRequest();
 request1.SearchIndex = "All";
 //request1.Keywords = table.Rows[i].ItemArray[0].ToString();
 request1.Keywords="9120031340270";
 request1.ItemPage = "1";
 request1.ResponseGroup = new string[] { "OfferSummary" };


 ItemSearchRequest request2 = new ItemSearchRequest();
 request2.SearchIndex = "All";
 //request2.Keywords = table.Rows[i+1].ItemArray[0].ToString();
 request2.Keywords = "9120031340300";
 request2.ItemPage = "1";
 request2.ResponseGroup = new string[] { "OfferSummary" };

                
 // batch the two requests together
 ItemSearch itemSearch = new ItemSearch();
 itemSearch.Request = new ItemSearchRequest[] { request1,request2 };
 itemSearch.AWSAccessKeyId = accessKeyId;

 // issue the ItemSearch request
 ItemSearchResponse response = client.ItemSearch(itemSearch);


 foreach (var item in response.Items[0].Item)
 {
 
 }
 foreach (var item in response.Items[1].Item)
 {
 

 }

是否可以通过设置 keywords = "9120031340256 and 9120031340270"

将这两个单独的请求组合成一个请求并让第一个请求返回 2 个项目

有人知道怎么做吗?

我需要专门搜索 UPC 吗?

最佳答案

从查看 API docs如果您想获得多个 UPC 的结果,我认为您可能想要使用 ItemLookup。

ItemLookup itemLookup = new ItemLookup(){
    AssociateTag = "myaffiliatetag-20"
};
itemLookup.AWSAccessKeyId = MY_AWS_ID;

ItemLookupRequest itemLookupRequest = new ItemLookupRequest();
itemLookupRequest.IdTypeSpecified = true;
itemLookupRequest.IdType = ItemLookupRequestIdType.UPC;
itemLookupRequest.ItemId = new String[] { "9120031340300", "9120031340270" };
itemLookupRequest.ResponseGroup = new String[] { "OfferSummary" };
itemLookup.Request = new ItemLookupRequest[] { itemLookupRequest };

ItemLookupResponse response = client.ItemLookup(itemLookup);
foreach(var item in response.Items[0])
{
  //Do something...
  Console.WriteLine(item.ItemAttributes.Title);
}

话虽这么说,如果您通过某些 ID(UPC、ASIN 等)进行查找,那么您进行批量关键字搜索的原始代码似乎是进行多个关键字搜索的唯一方法一个请求(我能找到..)。如果进行关键字搜索,您总是可以制作一个 ItemSearchRequest 生成器方法,以在创建倍数时减少重复代码。

关于c# - 亚马逊产品广告 API - 搜索多个 UPC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6447277/

相关文章:

c# - 初始化 USB 调制解调器的 COM 端口

c# - WPF setter 类

amazon-web-services - 提供来自 aws CloudWatch 警报的错误消息

amazon-web-services - 如何使用 aws CLI 获取 API key

c# - StaticResource 标记扩展与 System.Windows.Application.FindResource

c# - 如何通过Linq从xml中获取值

linux - 尝试在 ubuntu ec2 实例上安装某些东西

amazon-web-services - AWS cloudformation - 如何使用字符串参数来防止重复使用同一字符串

c# - 从 LINQ 查询结果填充 Observable 集合

amazon-web-services - 信任关系错误 AssumeRole 策略只能指定 STS AssumeRole 操作