CARI
KATEGORI
KATEGORI
Home / FORUM / All / Tech / ... / Templates & Scripts Stuff /
Cara Set Permission di API Drive v3
KASKUS
51
244
https://www.kaskus.co.id/thread/5e3ce783eaab254ba8549907/cara-set-permission-di-api-drive-v3

Cara Set Permission di API Drive v3

Jadi ceritanya begini saya kan punya web sharing file google drive, nah waktu saya menggunakannya, file yang di copy oleh aplikasi tersebut permission nya masih private, cara mengubah permission nya agar jadi anyone/publik bagaimana ya ?


Script di bawah tidak berhasil untuk set permission file yang di copy menjadi anyone/publik.


Ini code fuction yang saya gunakan:

Code:
function insertPermission($id,$token) { $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$id/permissions?key=$token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json", "Authorization: Bearer $token", "{"role":"reader","type":"anyone"}"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{"role":"reader","type":"anyone"}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
} function copyfile($id,$token) { $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$id/copy?access_token=$token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-length: 0", "Content-type: application/json", "Authorization: Bearer $token"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}


Ini code pemanggilnya:
Code:
$ruse = token("refresh",$_SESSION[email]);
            $copy = copyfile($share[file][file_id],$ruse[access_token]);
            insertPermission($copy[id],$ruse[access_token]);

            if($copy[id]) {

                echo "
                    <meta http-equiv="refresh" content="10;URL='https://docs.google.com/uc?id=$copy[id]'" />
                    <div class="my-3 p-3 bg-white rounded shadow">
                        <div style="padding: 50px 15px;text-align: center;background-color: #fff;">
                            <h3>Start Download</h3><br />
                            Click <a >here</a> for download.
                        </div>
                    </div>";

            }



GDP Network
© 2020 KASKUS, PT Darta Media Indonesia. All rights reserved
Ikuti KASKUS di