I'm quite new to php and I'm trying to use the imgur API (My code is based on several tutorials) What I'm trying to do is get an image from imgur display it on a web page. So I'm using this code
<?php
$client_id = '<ID>';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://api.imgur.com/3/image/rnXusiA');
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
?>
After converting $result
to an associative array, I'm trying to access data
$data = $json->data->link;
But there's nothing in $data
and I'm getting a Trying to get property of non-object
error. I'm assuming imgur didn't return any data. So what am I doing wrong?