繁体   English   中英

适用于 Asp.net 和 C# 的亚马逊产品广告 API

[英]Amazon Product Advertising API for Asp.net & C#

我想使用带有 asp.net 和 C# 的 Amazon Product Advertising API 获取书籍。 所有的指南和代码都令人困惑,以至于它们没有给您提供一种搜索书籍的方法。 是否有任何单个存根可用于调用服务并根据 ISBN 获取书籍。 谢谢

要获取书籍,请安装此库 (Install-Package Nager.AmazonProductAdvertising) https://www.nuget.org/packages/Nager.AmazonProductAdvertising/

例子:

var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.UK);
var result = await client.GetItemsAsync("978-0261102385");

您可以下载一个很好的示例解决方案。 http://aws.amazon.com/code/2480?_encoding=UTF8&queryArg=searchQuery&x=0&fromSearch=1&y=0&searchPath=code&searchQuery=Advertising

他们为您提供了一个名为 SignedRequestHelper 的类,然后您可以像这样拨打电话:

   public static void Main()
        {
            SignedRequestHelper helper = new SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION);

            /*
             * The helper supports two forms of requests - dictionary form and query string form.
             */
            String requestUrl;
            String title;

            /*
             * Here is an ItemLookup example where the request is stored as a dictionary.
             */
            IDictionary<string, string> r1 = new Dictionary<string, String>();
            r1["Service"] = "AWSECommerceService";
            r1["Version"] = "2009-03-31";
            r1["Operation"] = "ItemLookup";
            r1["ItemId"] = ITEM_ID;
            r1["ResponseGroup"] = "Small";

            /* Random params for testing */
            r1["AnUrl"] = "http://www.amazon.com/books";
            r1["AnEmailAddress"] = "foobar@nowhere.com";
            r1["AUnicodeString"] = "αβγδεٵٶٷٸٹٺチャーハン叉焼";
            r1["Latin1Chars"] = "ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJij";

            requestUrl = helper.Sign(r1);
            title = FetchTitle(requestUrl);

            System.Console.WriteLine("Method 1: ItemLookup Dictionary form.");
            System.Console.WriteLine("Title is \"" + title + "\"");
            System.Console.WriteLine();
}

您需要使用 ItemLookup(如示例),但将 IdType 设置为 ISBN。 然后将 ItemId 设置为实际的 ISBN。 以下是 ItemLookup 的详细信息:

docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ItemLookup.html

当我使用那个样本时,我得到了这个。 看起来最近 API 发生了变化。

System.InvalidOperationException: There is an error in the XML document. ---> Sy
stem.InvalidOperationException: <ItemLookupResponse xmlns='http://webservices.am
azon.com/AWSECommerceService/2011-08-01'> was not expected.

暂无
暂无

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

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