Skip to content

Instantly share code, notes, and snippets.

@tineyedev
Created April 30, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tineyedev/68ac6982483e12e47048fd8a75419291 to your computer and use it in GitHub Desktop.
Save tineyedev/68ac6982483e12e47048fd8a75419291 to your computer and use it in GitHub Desktop.
TinEye Commercial API image URL search PHP code sample
<?php
function search_url($api_url, $api_private_key, $api_public_key, $image_url) {
$p = array(
"offset" => "0",
"limit" => "100",
"image_url" => $image_url
);
$sorted_p = ksort($p);
$query_p = http_build_query($p);
$signature_p = strtolower($query_p);
$http_verb = "GET";
$date = time();
$nonce = uniqid();
$string_to_sign = $api_private_key . $http_verb . $date . $nonce . $api_url . $signature_p;
$api_sig = hash_hmac("sha256", $string_to_sign, $api_private_key);
$url = $api_url . "?api_key=" . $api_public_key . "&";
$url .= $query_p . "&date=" . $date . "&nonce=" . $nonce . "&api_sig=" . $api_sig;
$api_json_response = json_decode(file_get_contents($url), True);
if ($api_json_response['code'] == 200) {
print "status: Ok, ";
print "num results: " . $api_json_response['results']['total_results'];
} else {
print "status: Error, ";
}
return $api_json_response;
}
// SANDBOX KEYS
$api_url = "https://api.tineye.com/rest/search/";
$api_private_key = "6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^";
$api_public_key = "LCkn,2K7osVwkX95K4Oy";
echo var_dump(search_url($api_url, $api_private_key, $api_public_key, "https://tineye.com/images/meloncat.jpg"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment