Monday, 19 August 2013

JSON decode curl issue

JSON decode curl issue

Hi I'm trying to make this api call from wikipedia using this url, however
it says it's null when I dump the variable. This function works for my
other json api calls but not for this, I tested it in the broswer manually
it gives me a result. Here is my attempt
$url =
'http://en.wikipedia.org/w/api.php?action=query&format=json&titles=Image:Romerolagus
diazi (dispale) 001.jpg&prop=imageinfo&iiprop=url';
$result = apicall($url);
var_dump($result);
function apicall($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'MyBot/1.0 (http://www.mysite.com/)');
$result = curl_exec($ch);
if (!$result) {
exit('cURL Error: '.curl_error($ch));
}
$var = json_decode($result);
return $var;
}

No comments:

Post a Comment