Hi
I have class for operations with VWS in php, but i dont know authorize with my account.
Php code for target list:
$vuforia = new vuforiaTargetAPI("{server secret key}", "{server access key}"); $curlInfo = $vuforia->getTargetList();
public function getTargetList(){ $credentials = $this->createSignature("/targets"); return $this->getData($credentials, "https://vws.vuforia.com/targets"); }
Php code for submiting data:
public function getData($credentials, $target, $postType = "GET"){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: VWS ' .$credentials)); $page = curl_exec($ch); curl_close($ch); return $page; }
Php code for generating credentials:
private function createSignature($requestPath, $postType = "GET", $contentType = "", $content = ""){ $contentMD5 = md5($content); $date = new DateTime("now", new DateTimeZone("GMT")); $stringToSign = $postType . "\n" . $contentMD5 . "\n" . $contentType . "\n" . $date->format("D, d M Y H:i:s") . "\n" . $requestPath; $signature = base64_encode(hash_hmac('sha1', $stringToSign, $this->serverSecretKey)); $credentials = $this->serverAccessKey . ":" . $signature; return $credentials; }
$stringToSign for this example is
GETd41d8cd98f00b204e9800998ecf8427eFri, 21 Dec 2012 08:35:31/targets
Http header is
GET /targets HTTP/1.1 Host: vws.vuforia.com Accept: */* Authorization: VWS 08a061624dabe0c1871f9c93e680a38d8d073e19:NjY2ODI1OTMwZDhiZTk1NWNlMzFmYTRhNzkzN2ZmNjA3YTQ2MjY3YQ==
I m trying date in 3 different formats(Fri, 21 Dec 2012 08:35:31, Fri, 21 Dec 2012 08:43:49 +0000, Fri, 21 Dec 2012 08:35:31 GMT) and request path in 2 formats(/targets, https://vws.vuforia.com/targets). And now, i havent any idea what is wrong. Can you help me? If it post in wrong category please move it to right category.
Any luck
HI chiwo,
DId you had any luck in solving this issue? I'm in need of a PHP class as well, so I'm very interested whether you have solved the problem.
Best,
PIeter
What is the response that you
What is the response that you are getting from the Cloud Reco service? Also be sure to review our samples and API docs.
https://developer.vuforia.com/resources/dev-guide/managing-targets-cloud-database-using-developer-api
I've tried the PHP code below
I've tried the PHP code below and checked it against the Java code from the example. But I'm receiving the following response:
I've tried the PHP code below
I've tried the PHP code below and checked it against the Java code from the example. But I'm receiving the following response:
Response
Response was {"result_code":"AuthenticationFailure",....} Thanks to Sample code because in time when i downloaded samples, signature builder isnt included than i cant
Good to know. The samples
Good to know. The samples have been updated to include the SignatureBuilder. Which PHP has function are you using to obtain a correct text string?
I m used own function,
I m used own function, where $hex is result of hash_hmac function
private function hexToBase64($hex){
Thank you! I have now a
Thank you! I have now a working connection. If someone else needs this, below the functions I use, based on chiwo's work:
Thanks pieterdekker for
Thanks pieterdekker for sharing this code snippet; I am sure it will be useful to many others in the forum.
Thanks for the code
Hi, i have a question.
Hi c4m10, as always, I
Hi c4m10, as always, I recommend to carefully compare your implementation with the reference samples in Java;
pieterdekker might be able to share his (working) code also for the Post method (?)
c4m10 i think that you havent
c4m10 i think that you havent idea how vws authorization works. 95 percents of your code is by me.
Could you please help?
Hello chiwo,
@ all: if you would like to
@ all: if you would like to see some official PHP implementation (next to the Java samples that we provide already), it could also be a good idea for you to post an extra note in the wish-list section of our Forum ?
https://developer.vuforia.com/forum/general-discussion/wish-list
VWS Authorization problem
Hi everyone,
I'm using the chiwo code but i retrieve always {"result_code":"AuthenticationFailure","transaction_id":"cc7399b95c69491c8a3b8fc0c8447f5a"}.
VWS Authorization problem
I use this for date.
$date = new DateTime("now", new DateTimeZone("GMT"));
$datetime = $date->format("D, d M Y H:i:s ") . "GMT";
VWS Authorization problem
No way...
i always get {"result_code":"AuthenticationFailure","transaction_id":"a5faaf1682ec4dc6865e34aa800e26a8"}
VWS Authorization problem
How requestPath did you use? And are you sure that your secret and access keys are correct? And how type(get all targets, get target by id or other?) of request do you use?
VWS Authorization problem
@ Creadsmedia: not entering in the PHP discussion, but just a little note:
as Chiwo suggests, you may want to double-check that your keys are correct; for that you can also use our Java samples (those are guaranteed to work, if you use correct keys)
VWS Authorization problem
The requestPath is "/targets" ($credentials = $this->createSignature("/targets");)
The keys are corrects and postType it's a GET:
VWS Authorization problem
You need add datetime value from createSignature to getData method. That $datetime is same as $datetime in createSignature.
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: VWS " .$credentials,"DATE: ".$datetime));