Amazon product advertising api - c# sample

梦想的初衷 提交于 2020-01-15 03:15:07

问题


So I have been trying to get these API samples to work for three frustrating days. So far I still have had no success. I have tried about 10 different samples and of course none of them work. With some more digging the most up to date API I found was from april 2013 end even recent comments said that it worked. I knew it was just too good to be true and of course I didn't get it to work. I am pretty sure that i am missing something in that program.

here is the code:

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();

        }
    }
}

I get an error: The HTTP request was forbidden with client authentication scheme 'Anonymous'.

I did insert the AssociateTag value and the access key id but still it gives the same results.

here is the link i downloaded it from: http://dl.dropbox.com/u/119018/amazonProductAdvertisingAPI-SOAP-WCF-Updated.zip


回答1:


One problem could be is that you didn't put your AccessKeyId/SecretKey in all the required places. Please check your App.config once again and make sure you have set the following:

  <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>
....



回答2:


A alternative and simple way is using this nuget package Nager.AmazonProductAdvertising.

PM> Install-Package Nager.AmazonProductAdvertising

Example

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);


来源:https://stackoverflow.com/questions/19765959/amazon-product-advertising-api-c-sharp-sample

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!