亚马逊 API、产品广告 API、ItemSearch、C#
我正在尝试使用新产品亚马逊 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 循环时,没有返回任何项目(空),因此我收到空异常错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果上面的解决方案仍然不起作用。
试试这个..
下载示例代码
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.aspxwe 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..
这是一个 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