Amazon Product Advertising API Signature Code " error"

Discussion in 'Amazon' started by blogsite, Mar 14, 2011.

  1. #1
    Please someone help me,
    I get this error :

    Warning: file_get_contents(http://ecs.amazonaws.com/onca/xml?AWSAccessKeyId=AKIA........&AssociateTag=........-20&Keywords=harry+potter&Operation=ItemSearch&ResponseGroup=ItemAttributes,Offers,Images&SearchIndex=Books&Service=AWSECommerceService&Timestamp=&Version=2010-11-01&Signature=pqNYLF4%2...........PrcLc5U%3D) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/......./SimpleStore.php on line 56


    ItemSearch($_GET['SearchIndex'], $_GET['Keywords']);

    //Set up the operation in the request
    function ItemSearch($SearchIndex, $Keywords){

    //Set the values for some of the parameters.
    $AWSAccessKeyId = "AKIA------";
    $SecretAccessKey = "hH-------";
    $AssociateTag = "-------20";
    $Operation = "ItemSearch";
    $Version = "2010-11-01";
    $Service = "AWSECommerceService";
    $ResponseGroup = "ItemAttributes,Offers,Images";
    $String = "AWSAccessKeyId=$AWSAccessKeyId&AssociateTag=$AssociateTag&Keywords=$Keywords&Operation=$Operation&ResponseGroup=$ResponseGroup&SearchIndex=$SearchIndex&Service=$Service&Timestamp=$Timestamp&Version=$Version";
    $String = rawurldecode($Request);
    $String = str_replace("%7E", "~", $String);
    $String = preg_replace('/[\r\n\" "]/', '', $String);
    $String = preg_replace('#Keywords=(.*?)&([A-Za-z]+)=#e', '"Keywords=".preg_replace("/[^0-9a-zA-Z]/"," ","$1")."&".$2."=";', $String);
    $String = preg_replace('/[" "]+/', ' ', $String);
    $StringArray = explode( '?', $String, 2);
    $Parameters = explode("&", $StringArray[1]);
    $Parameters[] = "Timestamp=" .gmdate("Y-m-d\TH:i:s\Z");
    asort($Parameters);
    $NewString = implode("&", $Parameters);
    $NewString = rawurlencode($NewString);
    $NewString = str_replace("~", "%7E", $NewString);
    $NewString = str_replace("%3D", "=", $NewString);
    $NewString = str_replace("%26", "&", $NewString);
    $url = parse_url($StringArray[0]);
    $PrependString = "GET\n" .$url['host']. "\n" .$url['path']. "\n" .$NewString;
    $Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));
    $Signature = rawurlencode($Signature);
    $SignedRequest = $StringArray[0]. "?" . $NewString . "&Signature=" .$Signature;

    //for $SearchIndex and $Keywords
    $SearchIndex = "Books";
    $Keywords = "harry+potter";

    //Define the request
    $request=
    "http://ecs.amazonaws.com/onca/xml"
    . "?AWSAccessKeyId=" . $AWSAccessKeyId
    . "&AssociateTag=" . $AssociateTag
    . "&Keywords=" . $Keywords
    . "&Operation=" . $Operation
    . "&ResponseGroup=" . $ResponseGroup
    . "&SearchIndex=" . $SearchIndex
    . "&Service=" . $Service
    . "&Timestamp=" . $Timestamp
    . "&Version=" . $Version
    . "&Signature=" . $Signature;

    Please tell me what is wrong with this code.
     
    blogsite, Mar 14, 2011 IP
  2. Aff_Fan

    Aff_Fan Member

    Messages:
    147
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #2
    Why do you want to invent the wheel? Download free amazon script, make some money and buy paid script. Make money - don't waste your time.
     
    Aff_Fan, Mar 16, 2011 IP
  3. blogsite

    blogsite Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I know that the free scripts use they amazon associate id sometimes, The one in your signature will use my associate id all the time? and what the best paid script do you recommend me please?
     
    blogsite, Mar 16, 2011 IP
  4. Aff_Fan

    Aff_Fan Member

    Messages:
    147
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #4
    Yes, all the time. It's easy to test. All links to amazon use your associate id only.

    Associate-o-Matic $99.00 and Associate Store Script $9.95 (PHP or Joomla version - see my signature)
     
    Aff_Fan, Mar 16, 2011 IP
  5. blogsite

    blogsite Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    And what the difference between the Associate Store Script "free edition" and "paid edition" ?
     
    blogsite, Mar 16, 2011 IP
  6. Aff_Fan

    Aff_Fan Member

    Messages:
    147
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    35
    #6
    Free version - Category pagination disabled - Your visitors can't purchase all available items and limited to one page per category/subcategory.
     
    Aff_Fan, Mar 16, 2011 IP
  7. freshdevelopment

    freshdevelopment Notable Member

    Messages:
    1,303
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    240
    #7
    This looks like a temporary error from Amazon - is it happening every time?
     
    freshdevelopment, Mar 22, 2011 IP