AWS Item LookUp URL签名

问题描述 投票:1回答:2

我是AWS的新手,我正试图在我的UWP应用程序中通过UPC查找项目。我在向请求URL添加签名时遇到问题。我一直收到“我们计算的请求签名与您提供的签名不符。”

有任何打电话给亚马逊的经验吗?在大多数地方,api文档并不是真正针对C#。

    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();



    }


}

我有来自amazon scratchpad的网址对我自己的网址进行了评论,它们已经对齐,但我不能100%确定我是否正确地处理了签名。

任何帮助将不胜感激

凯文

c# amazon-web-services uwp amazon amazon-product-api
2个回答
1
投票

我还没有测试过以下内容。但是有关于你要求什么的文件。您是否检查了以下内容以创建签名?

首先,列出here的整个过程告诉我们您需要使用签名的URL

其次,关于如何使用C#和.NET创建URL签名,您可以参考以下文档:http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreateSignatureInCSharp.html

顺便说一句,您可以先查看示例code


1
投票

您可以使用以下nuget包。

PM> Install-Package Nager.AmazonProductAdvertising

查找示例

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

var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.UK);
var result = wrapper.Lookup("B00BYPW00I");
© www.soinside.com 2019 - 2024. All rights reserved.