简体   繁体   English

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

[英]Amazon Product Advertising API - searching for multiple UPCs

Using the Amazon Product Advertising API I am searching for 2 different UPCs:使用亚马逊产品广告 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)
 {


 }

Is it possible to combine these two separate requests into one request and just have the first request return 2 items by setting keywords = "9120031340256 and 9120031340270"是否可以将这两个单独的请求合并为一个请求,并通过设置keywords = "9120031340256 and 9120031340270"让第一个请求返回 2 个项目

Does anyone know how to do this?有谁知道如何做到这一点? I need to specifically search the UPC, is this the proper way to do this?我需要专门搜索 UPC,这是正确的方法吗?

From looking at the API docs I think you may want to use an ItemLookup if you want to get results for multiple UPCs.通过查看API 文档,我认为如果您想获得多个 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);
}

That being said, if you are not working with lookups by some ID (UPC, ASIN, etc) your original code of doing batched keyword searches appears to be only way to make multiple keyword searches in a single request (that I could find..).话虽如此,如果您使用某些 ID(UPC、ASIN 等)进行查找,那么您进行批量关键字搜索的原始代码似乎是在单个请求中进行多个关键字搜索的唯一方法(我可以找到.. )。 If doing keyword searches you could always make a ItemSearchRequest generator method to cut down on duplicate code when creating multiples.如果进行关键字搜索,您总是可以创建一个 ItemSearchRequest 生成器方法来减少创建倍数时的重复代码。

You can use the following nuget package.您可以使用以下nuget包。

PM> Install-Package Nager.AmazonProductAdvertising

Example例子

var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync(new string[] { "B00BYPW00I", "B004MKNBJG" });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM