Cloudinary REST api destroy 不起作用?

Cloudinary REST api destroy doesn't work?

我正在尝试删除 Cloudinary 中的图像,但它不起作用,我哪里做错了?

这段代码returns没有结果

$api_key = "----";
$api_secret = "---";
$timestamp = time();
$signature = sha1("timestamp=".$timestamp.$api_secret);

$postRequest = array(
'public_id' => "folder/sample_public_id",
'timestamp' => $timestamp,
'api_key' => $api_key,
'signature' => $signature,
'resource_type' => 'image',
'invalidate' => true);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.cloudinary.com/v1_1/CLOUDNAME/image/destroy");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postRequest));
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
print_r( curl_exec($ch) );

在没有关于该问题的更多详细信息的情况下,仅通过查看代码,我找到了一个可以解释为什么这样的请求没有成功的原因。

当您 generating authentication signatures 对 Cloudinary 的 API 调用时,除了 filecloud_name, resource_type 和你的 api_key.

在您的情况下,您只签署了 timestamp,但在您的请求中,您还传递了 public_idinvalidate 参数。因此,您需要将它们包含在您的签名生成行中。

注意参数签名时需要按字母顺序排序,api_secret在最后拼接。在这种情况下,生成签名的第 4 行应如下所示:

$signature = sha1("invalidate=true&public_id=folder/sample_public_id&timestamp=".$timestamp.$api_secret);

作为第一步,我建议进行上述更改并发送另一个请求。如果不成功,请使用其他信息更新 post。