簡體   English   中英

亞馬遜產品廣告 API - 搜索多個 UPC

[英]Amazon Product Advertising API - searching for multiple 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)
 {


 }

是否可以將這兩個單獨的請求合並為一個請求,並通過設置keywords = "9120031340256 and 9120031340270"讓第一個請求返回 2 個項目

有誰知道如何做到這一點? 我需要專門搜索 UPC,這是正確的方法嗎?

通過查看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);
}

話雖如此,如果您使用某些 ID(UPC、ASIN 等)進行查找,那么您進行批量關鍵字搜索的原始代碼似乎是在單個請求中進行多個關鍵字搜索的唯一方法(我可以找到.. )。 如果進行關鍵字搜索,您總是可以創建一個 ItemSearchRequest 生成器方法來減少創建倍數時的重復代碼。

您可以使用以下nuget包。

PM> Install-Package Nager.AmazonProductAdvertising

例子

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