我正在使用亞馬遜網絡服務獲取產品價格。亞馬遜產品搜索API:不工作
它工作正常,但是在亞馬遜在其中associateTag變爲強制參數的API進行了更改後,它開始給出錯誤。所以我把相關的標籤在請求爲:
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];
感謝。
今天我也遇到同樣的問題,現在他們需要associateTag,我已經放入了,我不會帶回任何結果...非常令人沮喪 – Standage 2012-02-21 21:17:03