php 通过API imgur删除图像

0dxa2lsx  于 4个月前  发布在  PHP
关注(0)|答案(2)|浏览(39)

我尝试使用图像ID从API中删除图像,而不是deletehash,因为当我上传图像时,它没有给予我deletehash。这是我尝试的。

$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);

字符串
如果我浏览图像URL,它仍然存在。

lx0bsm1f

lx0bsm1f1#

https://apidocs.imgur.com不给予您通过ID删除图像的可能性。
当你上传一张图片时,你应该有deletehash。使用它而不是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"
  },

字符串

fslejnso

fslejnso2#

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);

字符串
很难找到区别,如果有人可以启发我们。

相关问题