[英]Amazon product advertising api - c# sample
所以我一直在努力讓這些 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
一個問題可能是您沒有將 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>
....
另一種簡單的方法是使用這個 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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.