亚马逊 API、产品广告 API、ItemSearch、C#

发布于 2024-12-14 07:20:24 字数 1942 浏览 1 评论 0 原文

我正在尝试使用新产品亚马逊 API 来搜索亚马逊上的产品。我一直在查看他们的示例代码和其他人的示例,但我没有得到任何结果,想知道最近是否有其他人使用过该 API 并可以提供一些帮助?

using System;
using System.ServiceModel;
using Simple.Amazon.ECS;

namespace Simple {
    class Program {
        // your Amazon ID's
        private const string accessKeyId = "*******************";
        private const string secretKey = "************************************";

        // the program starts here
        static void Main(string[] args) {

            // create a WCF Amazon ECS client
            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(accessKeyId, secretKey));

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

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

            // issue the ItemSearch request
            ItemSearchResponse response = client.ItemSearch(itemSearch);

            // write out the results
            foreach (var item in response.Items[0].Item) {
                Console.WriteLine(item.ItemAttributes.Title);
            }
        }
    }
}

所有示例/示例在结构上都与此类似,但是当涉及 foreach 循环时,没有返回任何项目(空),因此我收到空异常错误。

I'm trying to get use the new product amazon API to search for products on Amazon. I've been looking at their sample code and other people's examples of this but I'm not getting back any results and wondering if anyone else has used the API recently and could provide some assistance?

using System;
using System.ServiceModel;
using Simple.Amazon.ECS;

namespace Simple {
    class Program {
        // your Amazon ID's
        private const string accessKeyId = "*******************";
        private const string secretKey = "************************************";

        // the program starts here
        static void Main(string[] args) {

            // create a WCF Amazon ECS client
            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(accessKeyId, secretKey));

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

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

            // issue the ItemSearch request
            ItemSearchResponse response = client.ItemSearch(itemSearch);

            // write out the results
            foreach (var item in response.Items[0].Item) {
                Console.WriteLine(item.ItemAttributes.Title);
            }
        }
    }
}

All the samples/examples are similar to this in structure but when it comes to the foreach loop there are no items returned(Null) so I get a null exception error.

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

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

发布评论

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

评论(2

九八野马 2024-12-21 07:20:24

如果上面的解决方案仍然不起作用。

试试这个..

下载示例代码 http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx< /a>

我们需要更新服务引用,对app.config、program.cs和reference.cs进行少量更改。

应用程序配置:
(1.)
appSettings 标签;
分配accessKeyId和secretKey值,
添加 。
(2.) 行为标签 ->端点行为标签 ->行为标签->签名行为标签;
分配accessKeyId和secretKey值。
(3.) 绑定标签 -> basicHttpBinding 标签; (选修的)
删除除 AWSECommerceServiceBindingNoTransport 之外的绑定标签
和 AWSECommerceServiceBindingTransport。
(4.) 客户标签;
删除除 AWSECommerceServiceBindingTransport 之外的端点标签。

程序.cs:
添加 itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"];在 ItemSearchResponse 响应 = amazonClient.ItemSearch(itemSearch) 之前;

reference.cs:(使用 Visual Studio 打开服务引用文件夹中的文件)
更改 private ImageSet[][] imageSetsField;到私有 ImageSet[] imageSetsField;
更改 public ImageSet[][] ImageSets {...} 为 public ImageSet[] ImageSets {...}

最后我们可以运行我们的程序并且它会工作。祝你好运..

注意:我使用 Microsoft Visual Studio 2010。
将会有 1 个警告(无效的子元素签名行为),我认为我们可以忽略它,或者如果您有任何解决方案请分享.. ^^v..

if the solution above still won't work.

try this one..

download the sample code on http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx

we need to update service references, make little change at app.config, program.cs, and reference.cs.

app.config:
(1.)
appSettings tag;
assign accessKeyId and secretKey value,
add .
(2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag;
assign accessKeyId and secretKey value.
(3.) bindings tag -> basicHttpBinding tag; (optional)
delete binding tag except AWSECommerceServiceBindingNoTransport
and AWSECommerceServiceBindingTransport.
(4.) client tag;
delete endpoint tag except AWSECommerceServiceBindingTransport.

program.cs:
add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

reference.cs: (open file in service references folder using visual studio)
change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField;
change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}

finally we can run our program and it will work. good luck..

nb: i use microsoft visual studio 2010.
there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..

⊕婉儿 2024-12-21 07:20:24

这是一个 wsdl 错误,我使用下面的链接来修复它:
https://forums.aws.amazon.com/thread.jspa?threadID=86989

This is a wsdl error, I use link below to fix it:
https://forums.aws.amazon.com/thread.jspa?threadID=86989

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