我想要使用新产品亚马逊API来搜索亚马逊上的产品。我一直在看他们的示例代码和其他人的例子,但我没有收到任何结果,并想知道是否有其他人最近使用过API并可以提供一些帮助?亚马逊API,产品广告API,ItemSearch,C#
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循环没有项目返回(NULL),所以我得到一个空的异常错误。
“响应”究竟包含什么内容? –
“未将对象引用设置为对象的实例”。当它到达foreach循环。 – Standage
希望我能告诉你什么是错的。我运行了我从[1]下载的代码,并按预期运行。 [1] http://flyingpies.wordpress。com/2009/08/01/17/ –