#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Consolidate Amazon Api


    Hello. I'm not sure if I'm in the correct forum, but here is the problem.

    I have registered with Amazon for their API's in all European countries. On my website, I want to consolidate and output the results from these countries when a search has been performed.

    At the moment I have this, for just 1 country (I've omitted irrelevant stuff), but would there be a php script to help accomplish what I want, and also to print out which amazon website the result came from...i.e. amazon.co.uk, amazon.es, amazon.de....?

    Thanks

    <?php
    $amazonAWSAccessKeyId = "aaa";
    $amazonSecretAccessKey = "bbb";
    $amazonAssociateTag = "ccc";


    function amazonSign($url,$secretAccessKey)
    {
    // 0. Append Timestamp parameter
    $url .= "&Timestamp=".gmdate("Y-m-d\TH:i:s\Z");

    // 1a. Sort the UTF-8 query string components by parameter name
    $urlParts = parse_url($url);
    parse_str($urlParts["query"],$queryVars);
    ksort($queryVars);

    // 1b. URL encode the parameter name and values
    $encodedVars = array();
    foreach($queryVars as $key => $value)
    {
    $encodedVars[amazonEncode($key)] = amazonEncode($value);
    }

    // 1c. 1d. Reconstruct encoded query
    $encodedQueryVars = array();
    foreach($encodedVars as $key => $value)
    {
    $encodedQueryVars[] = $key."=".$value;
    }
    $encodedQuery = implode("&",$encodedQueryVars);

    // 2. Create the string to sign
    $stringToSign = "GET";
    $stringToSign .= "\n".strtolower($urlParts["host"]);
    $stringToSign .= "\n".$urlParts["path"];
    $stringToSign .= "\n".$encodedQuery;

    // 3. Calculate an RFC 2104-compliant HMAC with the string you just created,
    // your Secret Access Key as the key, and SHA256 as the hash algorithm.
    if (function_exists("hash_hmac"))
    {
    $hmac = hash_hmac("sha256",$stringToSign,$secretAccessKey,TRUE);
    }
    elseif(function_exists("mhash"))
    {
    $hmac = mhash(MHASH_SHA256,$stringToSign,$secretAccessKey);
    }
    else
    {
    die("No hash function available!");
    }

    // 4. Convert the resulting value to base64
    $hmacBase64 = base64_encode($hmac);

    // 5. Use the resulting value as the value of the Signature request parameter
    // (URL encoded as per step 1b)
    $url .= "&Signature=".amazonEncode($hmacBase64);

    return $url;
    }
    // $q is set by both search.php and products.php
    if ($q)
    {
    // construct Amazon Web Services REST Query URL
    $url = "its the amazon url";
    $url .= "&Version=2009-03-01";
    $url .= "&Operation=ItemSearch";
    $url .= "&AWSAccessKeyId=".$amazonAWSAccessKeyId;
    $url .= "&AssociateTag=".$amazonAssociateTag;
    $url .= "&ResponseGroup=Medium";
    // sign
    $url = amazonSign($url,$amazonSecretAccessKey);
    $xml = file_get_contents($url);
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    How about learning PHP instead of just copypasting stuff you found somewhere? Then you could write your own code.

    Otherwise, I fear you'll have a hard time finding an existing script which does exactly what you want.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo