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

3

7

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?

Foofaraw answered 22/12, 2011 at 16:13 Comment(4)
I believe that the following still works flyingpies.wordpress.com/2009/08/01/17Latia
Nope is does not. The sample throws null reference exceptions due to most of the properties of the response object being null. Thanks for your effort thoughFoofaraw
I've just recently used that code to answer a similar question. The OP there was having the same issue as you are now having. I now believe that there may be an issue with the new associate tag requirement which would not effect my account until February but will affect any new accounts. Of course I could be incorrect but perhaps you should have a look at that question/answer any ways. https://mcmap.net/q/1325599/-search-amazon-example-with-new-amazon-serviceLatia
I compiled a fix for this API sample. Please find it here: forums.aws.amazon.com/message.jspa?messageID=440527#440527Housemaster
F
2

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

Foofaraw answered 18/1, 2012 at 15:0 Comment(0)
J
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("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US, "YourAssociateID");
var result = await client.GetItemsAsync("B0037X9N5U");
Jarrettjarrid answered 4/7, 2016 at 19:18 Comment(1)
@LiakatHossain wrapper.ErrorReceived += (errorResonse) => { System.Diagnostics.Debug.WriteLine(errorResonse.Error.Message); }; have you an error response here?Jarrettjarrid
D
1

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

Dudleyduds answered 24/5, 2012 at 8:46 Comment(1)
Link is dead as of 2016. This is why we ask people to post answers, not just links to answers.Norry

© 2022 - 2024 — McMap. All rights reserved.