【问题标题】:Amazon product advertising api - c# sample亚马逊产品广告 api - c# 示例
【发布时间】:2013-11-04 10:38:49
【问题描述】:

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

代码如下:

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

【问题讨论】:

  • 您注册了亚马逊网络服务吗?我想您需要指定 Amazon api 密钥..
  • 是的,我有。在网络服务和亚马逊员工中都有
  • 为了你想做的事;您是否指定了两个 api 密钥?亚马逊很少(如果有的话)允许匿名 api 请求。上面还有一个 AssociateTag 占位符,看起来您需要用与您的情况相关的值替换。
  • 是的,我已经替换了 associateTag 的值。我知道我的 api 键值,并且我已将这些值插入到每个样本中,包括这个。

标签: c# amazon ads


【解决方案1】:

一个问题可能是您没有将 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>
....

【讨论】:

  • 我完全错过了那部分。现在工作正常。谢谢!
  • @user2169586 您应该将此回复标记为正确/已回答。
【解决方案2】:

另一种简单的方法是使用这个 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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    相关资源
    最近更新 更多