AWS Item LookUp URL Signature

I'm new to AWS, I'm trying to lookup an item by UPC within my UWP App. I'm having issues adding the signature to the request URL. I keep receiving "The request signature we calculated does not match the signature you provided."

Has any had any experience with making calls to Amazon? There api documentation isn't really aimed towards C# in most places.

    public async void ItemLookup(string itemID)
    {
        Dictionary<string, string> fields = new Dictionary<string, string>();
        fields.Add("AssociateTag", associateTag);
        fields.Add("Condition", "All");
        fields.Add("IdType", "UPC");
        fields.Add("ItemId", itemID);
        fields.Add("Operation", "ItemLookup");
        fields.Add("ResponseGroup", "Large");
        fields.Add("SearchIndex", "All");
        fields.Add("Service", "AWSECommerceService");
        // fields.Add("Timestamp", Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:sssZ")));

        // Build Url for signing
        string url = string.Empty;
        foreach (var pair in fields)
        {
            url += "&" + pair.Key + "=" + pair.Value;
        }


        url = Uri.EscapeUriString(endpoint
                                + "AWSAccessKeyId=" + accessKeyId
                                + url);
        // Add Timestamp
        url += "&Timestamp=" + Uri.EscapeDataString(DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", CultureInfo.InvariantCulture));


        // URL        http://webservices.amazon.co.uk/onca/xml?AWSAccessKeyId=REMOVED&AssociateTag=REMOVED&Condition=All&IdType=UPC&ItemId=786936724943&Operation=ItemLookup&ResponseGroup=Large&SearchIndex=All&Service=AWSECommerceService&Timestamp=2017-11-22T11%3A34%3A42.602Z
        // SCRATCHPAD http://webservices.amazon.co.uk/onca/xml?AWSAccessKeyId=REMOVED&AssociateTag=REMOVED&Condition=All&IdType=UPC&ItemId=786936724943&Operation=ItemLookup&ResponseGroup=Large&SearchIndex=All&Service=AWSECommerceService&Timestamp=2017-11-22T09%3A20%3A35.000Z

        // &Signature=Lvqlenpx0wos4Hg6ZzSNHqOc1QwktXgt8nFHBTfTON4%3D



        Byte[] secretBytes = UTF8Encoding.UTF8.GetBytes(secretKey);
        HMACSHA256 hmac = new HMACSHA256(secretBytes);

        Byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(url);
        Byte[] hash = hmac.ComputeHash(dataBytes);
        String signature = Convert.ToBase64String(hash);

        // Full URL
        string requestURL = url + "&Signature=" + signature;

        HttpClient httpClient = new HttpClient();
        HttpResponseMessage responseMessage = await httpClient.GetAsync(requestURL);

        var response = await responseMessage.Content.ReadAsStringAsync();



    }


}

I have the url from amazon scratchpad commented out against my own url, they are aligned but I'm not 100% sure if I'm working on the signature correctly.

Any help would be greatly appreciated

Kevin


I haven't tested the following yet. But there are doc about what you ruquest. Have you checked the following to create your signature?

First, the whole process listed here told us that you need to use a signed URL

Second, for how to create a URL Signature Using C# and the .NET, you can refer to the following doc: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreateSignatureInCSharp.html

By the way, you can check the example code first.


You can use the following nuget package.

PM> Install-Package Nager.AmazonProductAdvertising

Lookup example

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

var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.UK);
var result = wrapper.Lookup("B00BYPW00I");
链接地址: http://www.djcxy.com/p/6652.html

上一篇: SpringFramework 3.0的Spring Web Flow配置还是其他选择?

下一篇: AWS Item LookUp URL签名