Muhammad Talha Muhammad Talha - 1 month ago 11
JSON Question

Trying simple search using envato api using php and curl

Can't figure out what is wrong with my code, Can anyone help.

$data1 = file_get_contents_curl("https://api.envato.com/v1/discovery/search/search/item?term=ajax%20chatbox");
print_r($data1);

function file_get_contents_curl($url) {
if (extension_loaded('curl') === true) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36");
curl_setopt($ch, CURLOPT_HEADER, array('Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxx'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
} else {
$data = file_get_contents($url);
}
return $data;
}


when i run this code then i got the following error

HTTP/1.1 403 Forbidden Access-Control-Allow-Origin: * Cache-Control: no-store Content-Type: application/json; charset=utf-8 ETag: W/"46-ad6fd84c" Expires: 0 Pragma: no-cache Vary: * X-Frame-Options: Deny X-Powered-By: Express Content-Length: 70 Date: Sat, 09 Apr 2016 06:56:57 GMT Connection: keep-alive {"error":"access_denied","error_description":"Bearer token not found"}

Answer

change

CURLOPT_HEADER

to

CURLOPT_HTTPHEADER
Comments