A step by step guide to using the verifeyed API.

This tutorial requires that you have signed up here for verifeyed API and have a set of public and private keys.

Objective

In this tutorial you will learn to use the verifeyed api by testing an image of your choice and obtaining the results. You can find the finished version of this tutorial here.

Step 1 : define your private and public key as variables for easy access

$privatekey = "your_private_key_here";
$apikey = "your_public_api_key_here";

Step 2 : The image to test

We assume the image to test is already placed online (eg by using an upload form) just define the url here. We will use the url of a test image stored on verifeyed server but you should try your own.

$iurl = "http://verifeyed.com/api/verifeyed_images/im/1.JPG"

Step 3 :Generate security protection variables

For security purpose, an random variable nonce has to be used which should only occur once in last 15 minutes. Based on this and other parameters we have, a signature is generated and sent to api. To prevent anyone hacking and resending your request , the signature is expired every 15 minutes, so it is important to have the correct time setup on your server. We will use a randomly generated fairly large value as nonce and then use this nonce , current time, the image url and the keys to generate the signature as below.

$nonce = substr(sha1(rand(0,9000000).time()),0,30);   // generate a 30 digit random nonce 
$date = time();
$SIG = $privatekey.'get'.$date.$nonce.'http://www.verifeyed.com/'."image_url=".strtolower($iurl)."";
$api_sig = sha1($SIG);              //encode it to hide private key

Note that the SIG generation is very important and , its best to copy-paste the particular line into your code to avoid any issue

Step 4:Call the API

We now call the api and send all our variables using the following . The returned values are json encoded so we will use the built in decode function to get the values as array

$APIAddress="http://www.verifeyed.com/api.php?image_url=$iurl&api_sig=$api_sig&api_key=$apikey&date=$date&nonce=$nonce";
$apidata = file_get_contents($APIAddress);   
$result = json_decode($apidata);
print_r($result);

The result is stored as an array in the $result variable. The finished sample can be downloaded here and can be used to test any image

Step 5:Print out the data

echo "
";
print_r($result);
echo "
";

If all is correct, this should give you the results as below

stdClass Object
(
    [stats] => stdClass Object
        (
            [timestamp] => 1389381815
            [query_time] => 3.4874
        )

    [code] => 1
    [result] => stdClass Object
        (
            [filename] => 1.JPG
            [result_code] => 1
            [make] => Canon
            [model] => Canon EOS 20D
            [width] => 3504
            [height] => 2336
            [format] => JPEG
            [datetime_original] => 2007:05:08 14:47:07
            [datetime_digitized] => 2007:05:08 14:47:07
            [datetime] => 2007:05:08 14:47:07
            [size] => 3182608
        )

)

More :

Based on this tutorial, a more re-usable class library with a test file is also available for php here.