使用新的亚马逊服务搜索亚马逊示例

发布于 2024-12-16 02:28:56 字数 1414 浏览 1 评论 0原文

我找不到新的亚马逊服务的工作示例(或者至少在过去几年内)。无论我在标题中输入什么内容,最接近的工作示例都会返回一个空项目。代码是:

        // Amazon ProductAdvertisingAPI client
        AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

        // prepare an ItemSearch request
        ItemSearchRequest request = new ItemSearchRequest();
        request.SearchIndex = "Books";
        request.Title = "C#";
        request.Condition = Condition.All;
        //request.ResponseGroup = new string[] { "Small" };

        ItemSearch itemSearch = new ItemSearch();
        itemSearch.Request = new ItemSearchRequest[] { request };
        itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"];

        // send the ItemSearch request
        ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

        // write out the results from the ItemSearch request
        foreach (var itemLst in response.Items)
        {
            if (itemLst.Item != null)
            {
                foreach (var item in response.Items[0].Item)
                {
                    Console.WriteLine(item.ItemAttributes.Title);
                }
            }
            else
                Console.WriteLine("No item info was found for this response list item.");
        }
        Console.WriteLine("<Done...press enter to continue>");
        Console.ReadLine();

我做错了什么?

I can not find a working example of the new amazon service (or at least, within the last couple of years). The closest working example just comes back with a null item no matter what I put in the title. The code is:

        // Amazon ProductAdvertisingAPI client
        AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

        // prepare an ItemSearch request
        ItemSearchRequest request = new ItemSearchRequest();
        request.SearchIndex = "Books";
        request.Title = "C#";
        request.Condition = Condition.All;
        //request.ResponseGroup = new string[] { "Small" };

        ItemSearch itemSearch = new ItemSearch();
        itemSearch.Request = new ItemSearchRequest[] { request };
        itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"];

        // send the ItemSearch request
        ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

        // write out the results from the ItemSearch request
        foreach (var itemLst in response.Items)
        {
            if (itemLst.Item != null)
            {
                foreach (var item in response.Items[0].Item)
                {
                    Console.WriteLine(item.ItemAttributes.Title);
                }
            }
            else
                Console.WriteLine("No item info was found for this response list item.");
        }
        Console.WriteLine("<Done...press enter to continue>");
        Console.ReadLine();

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

得不到的就毁灭 2024-12-23 02:28:56

我假设您已从此处下载了代码。如果这是正确的,那么您需要替换这一行:

AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

使用这些行:

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

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

// add authentication to the ECS client
amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

问题有两个:

  1. 您没有将 amazonClient 绑定到 HttpBinding
  2. 您没有签署请求

如果我的假设不正确,那么您应该从上面的链接下载代码,因为它是如何调用亚马逊产品 API 的工作示例。

I'm assuming that you've downloaded the code from here. If this is correct then you need to replace this line:

AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient();

With these lines:

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

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

// add authentication to the ECS client
amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

The problem is two fold:

  1. You are not binding the amazonClient to an HttpBinding
  2. You are not signing the request

If my assumption is incorrect then you should download the code from the above link as it is a working example of how to call the Amazon Product API.

度的依靠╰つ 2024-12-23 02:28:56

我相信您的问题可能是缺少关联标签。截至 2011 年 11 月,所有请求都需要这样做,并且我在测试初期就注意到,当我没有包含它时,我得到了空响应(带有错误代码)。我不确定这是否仍然是这种行为,但我肯定会假设如果您没有添加它(我在您的代码中没有看到),那么这可能是可疑的。

查看此处的顶部更改说明

如果您不这样做拥有 Associate ID,您需要申请一个。

I believe your problem may be lack of an Associate Tag. As of November, 2011, this is required for all requests and I noticed early on in my testing that I got null responses back (with an error code) when I didn't include it. I'm not sure if that's still the behavior but I'd definitely assume that if you aren't adding it (which I don't see in your code) that's a likely suspect.

Look at top change note here

If you don't have an Associate ID you will need to apply for one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文