使用JSON API删除Google Cloud存储桶对象

时间:2018-06-13 09:16:00

标签: object curl google-cloud-storage bucket php-curl

我们如何使用JSON API和php curl删除谷歌云存储对象。

1 个答案:

答案 0 :(得分:1)

    $obejct = rawurlencode ($obejct); // $object : object name

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/storage/v1/b/".BUCKET."/o/".$obejct);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $headers = array();
    $headers[] = "Authorization: Bearer ".$token;
    $headers[] = "Content-Type: application/http";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    echo $result