Is there an up-to-date c# sample for the Amazon product API?

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:12:42

问题


I'm trying to create a small application that interacts with the Product API of Amazon (get prices of articles, and so on)

Unfortunately all the C# samples for the interaction with the Amazon WCF service I've found so far are outdated. I know that Amazon decided that each service call must be signed with a personal accessKeyId and secretKey, so all minimal code samples that are older than 2009 (I think they made the change in 2009) are useless. The official Amazon documentation is useless to me as well, as it does not provide necessary information.

I've also googled two tutorial on how to access the API, and following these only result in no search results for any search tearm or simply null.

Is there an up-to-date (working!!) minimal sample somewhere available?


回答1:


So, I finally found the solution, based on a comment posted here: http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx This is also the URL, where I downloaded the code I made working.

I didn't pass my "Your unique Associates ID", which I didn't even had until just now. You can get it here: https://affiliate-program.amazon.com/

Add

itemSearch.AssociateTag = "YourAssociateID";

before amazonClient.ItemSearch(itemSearch).

Works like a charm




回答2:


I have found a up-to-date project, the code is available on github Nager.AmazonProductAdvertising

nuget

PM> install-package Nager.AmazonProductAdvertising

Example

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

var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE, "YourAssociateID");
var result = wrapper.Lookup("B0037X9N5U");



回答3:


if the solution above still won't work.

try this one.. (i use microsoft visual studio 2010)

download the sample code on http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx

we need to update service references, make little change at app.config, program.cs, and reference.cs.

app.config:
(1.)
appSettings tag; assign accessKeyId and secretKey value, add
<add key="associateTag" value="yourAssociateTag" />.
(2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag; assign accessKeyId and secretKey value.
(3.) bindings tag -> basicHttpBinding tag; (optional) delete binding tag except AWSECommerceServiceBindingNoTransport and AWSECommerceServiceBindingTransport.
(4.) client tag;
delete endpoint tag except AWSECommerceServiceBindingTransport.

program.cs:
add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

reference.cs: (open file in service references folder using visual studio)
change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField;
change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}

finally we can run our program and it will work. good luck..

nb: there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..



来源:https://stackoverflow.com/questions/8606657/is-there-an-up-to-date-c-sharp-sample-for-the-amazon-product-api

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