有没有更有效的方式来应对亚马逊的商品广告API在C#ASP.NET(ESP MVC 5)?亚马逊、更有效、方式、商品

2023-09-11 10:37:52 作者:南顾生烟

我终于拿到了亚马逊的产品广告API来在我的MVC的5个网站。我使用提供了从亚马逊网站下载内容之一的SignedRequestHelper级。其实我已经得到了裁判的亚马逊API,但我似乎没有使用它在所有的present。

I have finally got the Amazon product advertising API to work on my MVC 5 site. I am using the "SignedRequestHelper" class that was provided on one of the downloads from the Amazon site. I have actually got a ref to the Amazon API but I do not seem to be using it at all at present.

我所用至今(控制器):

What I am using so far is (controller):

    SignedRequestHelper helper = new SignedRequestHelper("myAWSaccessKeyID",
    "mysecretKey", "webservices.amazon.co.uk");


    Dictionary<String, String> items = new Dictionary<String, String>();

    items.Add("Service", "AWSECommerceService");
    items.Add("Operation", "ItemSearch");
    items.Add("AWSAccessKeyId", "myAWSaccessKeyID");
    items.Add("AssociateTag", "myTag");
    items.Add("SearchIndex", SearchIndex);//This is a string value (selectbox)
    items.Add("ResponseGroup", "Images,ItemAttributes,OfferFull,Offers,OfferSummary,Reviews");
    items.Add("Keywords", keyword);//This is a string value

    string requestUrl = helper.Sign(items);

    ViewBag.Stuff = requestUrl;//Just so I could see the whole URL!

    WebRequest request = HttpWebRequest.Create(requestUrl);
    WebResponse response = request.GetResponse();
    XmlDocument doc = new XmlDocument();
    doc.Load(response.GetResponseStream());

    XmlNodeList titleNodes = doc.GetElementsByTagName("Item");

    ViewBag.Titles = titleNodes;

您可能会注意到我部分地从便笺复制的JAVA code的风格。

You may notice I partially the copied the style of JAVA code from the scratch pad.

这一点上的看法我只是处理每一部分,因为它涉及。这是一种混乱和可怕和处理这样的开关:

From that point on in the view I just deal with each part as it comes. It is kind of messy and horrid and dealing with switches like this:

foreach (System.Xml.XmlNode item in ViewBag.Titles)
{
    <h3>Item: @count</h3>
    foreach (System.Xml.XmlNode child in item.ChildNodes)
    {
        switch (child.Name)
        {
            case "ASIN":
                <p>ASIN: @child.InnerText</p>
                break;
            case "MediumImage":
                <img src="@child.ChildNodes[0].InnerText" />
                break;
            case "ItemAttributes":
                foreach (System.Xml.XmlNode child1 in child.ChildNodes)
                {
                    if(child1.Name == "Title")
                    {
                        <p>@child1.InnerText</p>
                    }
                }
                break;
        }

    }
    count++;
}

它的工作原理,我可以用XML文档等等。我只需要知道,如果有一种方法,使其实际使用被赋予作为参考API部分去改变它。我宁愿用比原始的XML这样做适当的工具。我有这样的困难,我基本上只是试图在JAVA风格code连接在亚马逊的暂存器亚马逊的文档连接。

It works and I can use the XML document etc. I just need to know if there is a way to change it so that it is actually using the API part that was given as a reference. I would rather use proper tools than do it with raw XML like this. I had such difficulty connecting with the Amazon documentation that I basically just tried to connect in the JAVA style code on Amazon's scratchpad.

推荐答案

我相信,我终于找到了一种方法,现在使用的实际亚马逊督促高级API。这个问题正在如何登录使用最新的API请求(即我又增加了作为参考)。基准溶液中加入以类似的方式来使用入门指南即使被并参考VS2005。这显然​​是10岁,但我不知何故没有得到它带着几分解决问题的工作。我从来没有得到正确的签名,所以我结束了使用那个可怕的REST bodge(在我原来的问题)!

I believe that I have finally found a way to use the actual Amazon Prod Adv API now. The problem was working out how to sign the request using the latest API (that I had added as a reference). The reference was added in a similar way to the getting started guide even though that was making reference to VS2005. That is obviously 10 years old but I somehow did get it working with a bit of problem solving. I just never got the signing correct so I ended up using that horrid REST bodge (in my original question)!

现在已经帮助过我的职位是这一个: amazon产品广告API - 项目查找请求工作的例子

The post that has helped me now is this one: amazon product advertising api - item lookup request working example

这是一个标记为答案。它只有4个了,票却是我发现的最好的事情。我把所有的类到控制器对其进行测试,但我现在必须使用模式或扩展类,做正确。它的工作无论如何虽然。

It is the one marked as the answer. It has only 4 up-votes but it is the best thing I have found. I put all the classes into the controller to test it but I will now have to do it properly using models or extension classes. It worked anyway though.