gpt4 book ai didi

asp.net - 使用 Asp.net 的亚马逊图书搜索 API

转载 作者:行者123 更新时间:2023-12-04 21:25:19 24 4
gpt4 key购买 nike

如何使用 amazon API 在 asp.net 中使用 ISBN 号搜索书籍?

最佳答案

http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
使用 svcutil.exe 为上面给定的 url 创建代理
然后这是 GetBookByISBN 的方法。 AmazonBook 是我的自定义 DTO,您必须自己创建。

public static AmazonBook GetBookByISBN(string ISBN)
{
WebConfigHelper wch = new WebConfigHelper("AWSSettings");
AmazonBook book = null;
string AWSAccessKeyId = wch["AccessKey"];
string AssociateTag = wch["AssociateTag"];
string AWSSecKey = wch["SecretKey"];

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxReceivedMessageSize = int.MaxValue;

AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(
binding,
new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

// add authentication to the ECS client
client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(AWSAccessKeyId, AWSSecKey));


ItemSearchRequest request = new ItemSearchRequest();
request.SearchIndex = "Books";
request.Power = "ISBN:" + ISBN.Trim();
request.ResponseGroup = new string[] { "Large" };
request.Sort = "salesrank";

ItemSearchRequest[] requests = new ItemSearchRequest[] { request };

ItemSearch itemSearch = new ItemSearch();
itemSearch.AWSAccessKeyId = AWSAccessKeyId;
itemSearch.AssociateTag = AssociateTag;
itemSearch.Request = requests;


try
{
ItemSearchResponse response = client.ItemSearch(itemSearch);
Items info = response.Items[0];
if (info.Item != null)
{
Item[] items = info.Item;
if (items.Length == 1)
{
book = new AmazonBook(items[0]);
}
}
}
catch (Exception ex)
{
throw ex;
}
return book;


}

问候,

关于asp.net - 使用 Asp.net 的亚马逊图书搜索 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4335636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com