Kaskus

Tech

adispin2Avatar border
TS
adispin2
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>";

            }

0
286
0
GuestAvatar border
Komentar yang asik ya
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan