亚马逊产品搜索API:不工作

时间:2012-02-21 08:10:27

标签: amazon-web-services amazon amazon-product-api

我正在使用亚马逊网络服务来获得产品Price。

它工作正常但是在亚马逊在API中进行了更改后,其中associateTag成为强制参数,它开始给出错误。所以我在请求中放了一个关联的标签:

tempQueryString =[NSString stringWithFormat:@"GET\necs.amazonaws.com\n/onca/xml\nAWSAccessKeyId=AKIAJ3A3LA5NYXWPSTGQ&IdType=ASIN&ItemId=B003VKR0J0&MerchantId=Amazon&AssociateTag=babyformu-20&Operation=ItemLookup&ResponseGroup=Large&Service=AWSECommerceService&SignatureVersion=2&SignatureMethod=HmacSHA256&Timestamp=%@T%@%@%@Z&Version=2010-01-01",str2,hour,mint,s];

现在给出了这个错误:
"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."

我没有对签名方法进行任何更改。 这是:

NSString *key = @"9at/FN4mouFxnIV2SsoQTR4iO6x6AWVt2xFvEwmv"; // private key
    NSLog(@"current:    %@ ",queryString);
    NSString *data = queryString;
    const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
    const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
    unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
    CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
    NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC
                                          length:sizeof(cHMAC)];
    hash = [HMAC base64Encoding];
    NSLog(@"hash value11 == %@",hash);
    encodedString = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)hash, NULL, CFSTR(":/?#[]@!$&’()*+,;="), kCFStringEncodingUTF8);

我正在使用此api来获取产品详细信息:

query=[NSString stringWithFormat:@"http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIAJ3A3LA5NYXWPSTGQ&IdType=ASIN&ItemId=B003VKR0J0&AssociateTag=babyformu-20&MerchantId=Amazon&Operation=ItemLookup&ResponseGroup=Large&Service=AWSECommerceService&Timestamp=%@T%@:%@:%@Z&Version=2009-03-31&Signature=%@",str2,h,m,s,encodedString];

提前致谢。

1 个答案:

答案 0 :(得分:0)

我能够相对轻松地修复我的亚马逊代码。我正在使用PHP。我刚刚添加了另一个参数:

$parameters["AssociateTag"] = myInfo::MY_AMAZON_ASSOCIATE_ID;

然后我打电话给:

aws_signed_request("com", $parameters, $this->public_key, $this->private_key)

AWS签名请求由Ulrich Mierendorff创建,并由Sameer Borate修改。