亚马逊产品广告api - c#sample

时间:2013-11-04 10:38:50

标签: c# amazon advertising

所以我一直试图让这些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请求被禁止使用客户端身份验证方案“Anonymous”。

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

这是我从http://dl.dropbox.com/u/119018/amazonProductAdvertisingAPI-SOAP-WCF-Updated.zip

下载的链接

2 个答案:

答案 0 :(得分: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>
....

答案 1 :(得分:3)

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

PM> Install-Package Nager.AmazonProductAdvertising

示例

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

var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
var result = wrapper.Search("canon eos", AmazonSearchIndex.Electronics, AmazonResponseGroup.Large);