使用新的亚马逊服务搜索亚马逊示例
我找不到新的亚马逊服务的工作示例(或者至少在过去几年内)。无论我在标题中输入什么内容,最接近的工作示例都会返回一个空项目。代码是:
// 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您已从此处下载了代码。如果这是正确的,那么您需要替换这一行:
使用这些行:
问题有两个:
如果我的假设不正确,那么您应该从上面的链接下载代码,因为它是如何调用亚马逊产品 API 的工作示例。
I'm assuming that you've downloaded the code from here. If this is correct then you need to replace this line:
With these lines:
The problem is two fold:
amazonClient
to an HttpBindingIf 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.
我相信您的问题可能是缺少关联标签。截至 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.