0

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.

  • When you send the request, what is the response you get from the server? – Progman Jul 29 '18 at 11:12
  • According to https://apidocs.imgur.com you must send a DELETE request for deleting the image, not GET. – Progman Jul 29 '18 at 11:14
  • Ok I will try with delete then and let you know. –  Jul 29 '18 at 11:40
  • it says authentication required –  Jul 29 '18 at 12:30
  • Please edit your question to include the new source code you have and the full response you get from the server. – Progman Jul 29 '18 at 12:32
  • I have edited the code, {"data":{"error":"Authentication required","request":"\/3\/image\/pNAHgGq2WvXAUey","method":"DELETE"},"success":false,"status":401}bool(true) –  Jul 29 '18 at 12:39
  • It looks like `pNAHgGq2WvXAUey` is not a delete hash or your client Id is invalid. You might want to debug your CURL request with https://stackoverflow.com/questions/3757071/php-debugging-curl#14436877 to check the data you are sending. – Progman Jul 29 '18 at 12:56

2 Answers2

0

https://apidocs.imgur.com doesn't give you the possibility to delete image by ID.

When you uploading an image you should have deletehash. Use it instead of id.

data": {
    "id": "orunSTu",
    "title": null,
    "description": null,
    "datetime": 1495556889,
    "type": "image/gif",
    "animated": false,
    "width": 1,
    "height": 1,
    "size": 42,
    "views": 0,
    "bandwidth": 0,
    "vote": null,
    "favorite": false,
    "nsfw": null,
    "section": null,
    "account_url": null,
    "account_id": 0,
    "is_ad": false,
    "in_most_viral": false,
    "tags": [],
    "ad_type": 0,
    "ad_url": "",
    "in_gallery": false,
    "deletehash": "x70po4w7BVvSUzZ",
    "name": "",
    "link": "http://i.imgur.com/orunSTu.gif"
  },
kallosz
  • 521
  • 3
  • 10
0
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.

  • The image delete hash is different, you might have authorization for deleting that image, but not the other one. That's why the server is saying "Authentication required". – Progman Jul 29 '18 at 13:10
  • I think the difference is curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); hash is different cause I am uploading again and again to test. –  Jul 29 '18 at 13:26