开发者

ASP.NET Amazon ItemSearch

Does anyone know of any good examples, or开发者_如何学JAVA care to explain how to do an amazon lookup similar to this, http://blogs.msdn.com/b/coding4fun/archive/2006/10/31/912260.aspx, I would just use this, but it seems to be out of date and the source is no longer available. Ideal What i would like to be able to do is look up items on either keyword such as "star trek" or straight up UPC. What I would like to get back is title, description, year, and a link to an image, type (dvd, books, music). Any help would be great, thanks.


I wrote a little C# Wrapper for Amazon ItemLookup that hands you back a handy object graph. It only supports ItemLookup right now. I have the source up on BitBucket.

You can make calls like:

var item = client.LookupByAsin("B0037X9N5U");
double? price = item.GetLowestPrice();


The SprightlySoft AWS Component for .NET allows you to interact will Amazon's Product Advertising API. Here is sample code for looking up an item based on UPC. Get the component for free at http://sprightlysoft.com/. The component comes with sample code that shows you how to do an ItemSearch with the Product Advertising API.

//Product Advertising API, ItemLookup: http://docs.amazonwebservices.com/AWSECommerceService/2010-10-01/DG/ItemLookup.html

SprightlySoftAWS.REST MyREST = new SprightlySoftAWS.REST();

String RequestURL;
RequestURL = "https://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&Version=2010-10-01";
RequestURL += "&AWSAccessKeyId=" + System.Uri.EscapeDataString(TextBoxAWSAccessKeyId.Text) + "&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z"));
RequestURL += "&ItemId=025192022272";
RequestURL += "&IdType=UPC";
RequestURL += "&SearchIndex=DVD";

String RequestMethod;
RequestMethod = "GET";

String SignatureValue;
SignatureValue = MyREST.GetSignatureVersion2Value(RequestURL, RequestMethod, "", TextBoxAWSSecretAccessKey.Text);

RequestURL += "&Signature=" + System.Uri.EscapeDataString(SignatureValue);

Boolean RetBool;
RetBool = MyREST.MakeRequest(RequestURL, RequestMethod, null);
System.Diagnostics.Debug.Print(MyREST.LogData);

if (RetBool == true)
{
    String ResponseMessage = "";
    System.Xml.XmlDocument MyXmlDocument;
    System.Xml.XmlNamespaceManager MyXmlNamespaceManager;
    System.Xml.XmlNode MyXmlNode;
    System.Xml.XmlNodeList MyXmlNodeList;

    MyXmlDocument = new System.Xml.XmlDocument();
    MyXmlDocument.LoadXml(MyREST.ResponseString);

    MyXmlNamespaceManager = new System.Xml.XmlNamespaceManager(MyXmlDocument.NameTable);
    MyXmlNamespaceManager.AddNamespace("amz", "http://webservices.amazon.com/AWSECommerceService/2010-10-01");

    MyXmlNodeList = MyXmlDocument.SelectNodes("amz:ItemLookupResponse/amz:Items/amz:Item", MyXmlNamespaceManager);

    if (MyXmlNodeList.Count == 0)
    {
        ResponseMessage = "Item not found.";
    }
    else
    {
        foreach (System.Xml.XmlNode ItemXmlNode in MyXmlNodeList)
        {
            MyXmlNode = ItemXmlNode.SelectSingleNode("amz:ItemAttributes/amz:Title", MyXmlNamespaceManager);
            ResponseMessage += "Title = " + MyXmlNode.InnerText;

            ResponseMessage += Environment.NewLine;
        }
    }

    MessageBox.Show(ResponseMessage);
}
else
{
    MessageBox.Show(MyREST.ResponseStringFormatted);
}


Hi it is very easy with the following nuget Nager.AmazonProductAdvertising package

nuget

PM> Install-Package Nager.AmazonProductAdvertising

Example

var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US);
var result = await client.GetItemsAsync("B0037X9N5U");


There's a whole set of examples on amazon's website: http://aws.amazon.com/code/Product%20Advertising%20API?_encoding=UTF8&jiveRedirect=1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜