2

所以我一直在努力让这些 API 示例工作了三天,令人沮丧。到目前为止,我仍然没有成功。我尝试了大约 10 种不同的样品,当然它们都不起作用。随着更多的挖掘,我发现最新的 API 是从 2013 年 4 月开始,甚至最近的评论都说它有效。我知道这太好了,不可能是真的,当然我没有让它发挥作用。我很确定我在那个程序中遗漏了一些东西。

这是代码:

namespace Amazon.PAAPI
{
    class Program
    {

        static void Main(string[] args)
            {

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


            // 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 = ConfigurationManager.AppSettings["accessKeyId"];
            itemSearch.AssociateTag = "ReplaceWithYourValue";

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

            // write out the results from the ItemSearch request
            foreach (var item in response.Items[0].Item)
            {
                Console.WriteLine(item.ItemAttributes.Title);
            }
            Console.WriteLine("done...enter any key to continue>");
            Console.ReadLine();

        }
    }
}

我收到一个错误:客户端身份验证方案“匿名”禁止 HTTP 请求。

我确实插入了AssociateTag值和访问密钥 ID,但它仍然给出了相同的结果。

这是我下载的链接:http: //dl.dropbox.com/u/119018/amazonProductAdvertisingAPI-SOAP-WCF-Updated.zip

4

2 回答 2

7

一个问题可能是您没有将 AccessKeyId/SecretKey 放在所有必需的位置。请再次检查您的 App.config 并确保您已设置以下内容:

  <appSettings>
    <add key="amazonSecurityNamespace"  value="http://security.amazonaws.com/doc/2007-01-01/" />
    <add key="accessKeyId"  value="**{put your Id here}**" />
    <add key="secretKey"  value="**{put your key here}**" />
  </appSettings>
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="signingBehavior" type="Amazon.PAAPI.WCF.AmazonSigningBehaviorExtensionElement, Amazon.PAAPI.WCF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="amazonEndpointBehavior">
          <signingBehavior accessKeyId="**{put your Id here}**" secretKey="**{put your key here}**" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
....
于 2013-11-04T12:52:25.117 回答
3

另一种简单的方法是使用这个 nuget 包Nager.AmazonProductAdvertising

PM> Install-Package Nager.AmazonProductAdvertising

例子

var authentication = new AmazonAuthentication();
authentication.AccessKey = "accesskey";
authentication.SecretKey = "secretkey";

var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.DE);
var result = await client.SearchItemsAsync("canon eos");
于 2016-03-28T09:33:41.377 回答