Very strange!This error makes me crazy!

Discussion in 'Amazon' started by windflow, Nov 13, 2009.

  1. #1
    I am using amazon advertising api.There is a big problem i came cross.
    I used this unsigned url:
    http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService
    &Version=2009-10-01
    &Operation=ItemSearch
    &SearchIndex=Apparel
    &BrowseNode=1046310
    &Brand=Ray-Ban
    &ResponseGroup=ItemAttributes,Offers,Images,SearchBins
    &MerchantId=All
    then i got signed url below via Signed Requests Helper and this signed url works well.
    http://ecs.amazonaws.com/onca/xml?A...=ZVgn6fDrlnslT80lXqsGDk7NEmmCpUtysiLIlMHM3OA=

    But,in my php file,there is always an error said signature is not a valid value .
    Here is my php code:
    $AWSAccessKeyId = "AKIAJ5XYNA22LKPKD54Q";
    $SecretAccessKey = "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";
    $Timestamp = gmdate("Y-m-d\TH:i:s\Z");
    $ResponseGroup = "ItemAttributes,Offers,Images,SearchBins";
    $Node="1046310";

    $String = "AWSAccessKeyId=$AWSAccessKeyId&
    BrowseNode=1046310&
    Brand=Ray-Ban&
    MerchantId=All&
    Operation=ItemSearch&
    ResponseGroup=$ResponseGroup&
    SearchIndex=Apparel&
    Service=AWSECommerceService&
    Timestamp=$Timestamp&
    Version=2009-10-01";

    $String = preg_replace('/[\r\n]/', '', $String);
    $String = str_replace("%3D", "=", str_replace("%26", "&", rawurlencode($String)));
    $Prepend = "GET\necs.amazonaws.com\n/onca/xml\n";
    $PrependString = $Prepend . $String;
    $Signature = rawurlencode(base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True)));

    $BaseUrl = "http://ecs.amazonaws.com/onca/xml?";
    $SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;

    $XML = simplexml_load_file($SignedRequest);

    BTW,my code works well after i delete string "Brand=Ray-Ban" .
    Why! i am already crazy!
     
    windflow, Nov 13, 2009 IP
  2. appleranger

    appleranger Peon

    Messages:
    339
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This sounds pretty technical. Contact their support team for this one.
     
    appleranger, Nov 14, 2009 IP
  3. windflow

    windflow Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have found the reason .
     
    windflow, Nov 14, 2009 IP
  4. johngfcarey

    johngfcarey Peon

    Messages:
    446
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can you post it.
     
    johngfcarey, Nov 14, 2009 IP
  5. windflow

    windflow Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Name-value pairs must be sorted from A to Z.
     
    windflow, Nov 14, 2009 IP
  6. Raditz

    Raditz Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks ...........
     
    Raditz, Nov 14, 2009 IP