Monday, 15 July 2013

api - The request signature we calculated does not match AMAZON AWS PHP -



api - The request signature we calculated does not match AMAZON AWS PHP -

i have looked @ samples of code based on issue on stack overflow still cant request work. maintain getting error:

<error><code>signaturedoesnotmatch</code><message>the request signature calculated not match signature provided. check aws secret access key , signing method. consult service documentation details.

here code:

$access_key = "access_key"; $associatetag = "aossociate_tag"; $secretkey = "secret_key"; $keywords = "harry%20potter"; $timestamp = gmdate("y-m-d\th:i:s\z"); $operation = "awsecommerceservice"; function createsignature($operation,$timestamp,$secretkey){ $the_string=$operation.$timestamp; homecoming base64_encode(hash_hmac("sha256",$the_string,$secretkey,true)); } $signature = createsignature ($operation,$timestamp,$secretkey); $apicall = "http://ecs.amazonaws.com/onca/xml?". "awsaccesskeyid=$access_key&". "associatetag=$associatetag&". "browsenode=1000&". "itempage=1&". "keywords=$keywords&". "operation=itemsearch&". "responsegroup=medium&". "searchindex=books&". "service=awsecommerceservice&". "timestamp=$timestamp&". "version=2011-08-01&". "signature=$signature"; $response = simplexml_load_file($apicall);

can help?

i had issue long time , worked me code :

require_once 'crypt/hmac.php'; require_once 'http/request.php'; $keyid = "adasdasd"; $secretkey = "asdasdasdasdasd+"; function hex2b64($str) { $raw = ''; ($i=0; $i < strlen($str); $i+=2) { $raw .= chr(hexdec(substr($str, $i, 2))); } homecoming base64_encode($raw); } function constructsig($str) { global $secretkey; $str = utf8_encode($str); $secretkey = utf8_encode($secretkey); $hasher =& new crypt_hmac($secretkey, "sha1"); $signature = hex2b64($hasher->hash($str)); homecoming ($signature); } $expire = time()+1000; $resource = "/demo/files/clouds.jpg"; $date = gmdate("d, d m y g:i:s t"); $mime = "image/jpeg"; $stringtosign = "put\n"; $stringtosign .= "\n"; $stringtosign .= "$mime\n"; $stringtosign .= "$date\n"; $stringtosign .= $resource; $req =& new http_request("http://nameofmine.s3.amazonaws.com/files/clouds.jpg"); $req->setmethod("put"); $req->addheader("date",$date); $req->addheader("authorization", "aws " . $keyid . ":" . constructsig($stringtosign)); $req->addheader("content-type",$mime); $req->setbody(file_get_contents($file_path)); $req->sendrequest(); $responsecode = $req->getresponsecode(); $responsestring = $req->getresponsebody(); echo $responsecode;

as see have utilize crypto, http pear plugins

php api amazon-web-services amazon

No comments:

Post a Comment