Search code examples
phpimgur

imgur delete image via api


I tried to delete image from api using image id and not deletehash, because when I uploaded image, it didn't give me deletehash. Here is what I tried.

$client_id = "xxxxxxxxxxxxxxxxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image/pNAHgGq2WvXAUey');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
var_dump($result);

If I browse the image url, it is still there.


Solution

  • Ok guys following code worked,
    
    $client_id = "xxxxxxxxxxxxxxxx";
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, "https://api.imgur.com/3/image/"."lm1sOhLidoThyoW");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    
    
    $headers = array();
    $headers[] = "Authorization: Client-ID ".$client_id;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    var_dump($result);
    

    Hard to find the difference, if someone can please enlighten us.