I have a Google workspace account, and I am creating a php panel to manage the team drives, I can already create the drive and add users, the problem is when I have to remove the user from the team drive, I am not able to.
When I create the drive my user is already in the drive as an administrator what I want to do is add two users and remove mine, from the Google drive panel this is possible, but I am not able to remove my user with the api.
//Create the team drive
$requestId = $this->user->id.time();
$client = new ApiGoogleDrive(1000);
try {
$teamDrive = $client->createDrive($requestId , $data["name"]);
//var_dump($teamDrive);
//saves the data of the created drive in the database
$myDrive->id_user = $this->user->id;
$myDrive->id_drive = $teamDrive->getId();
$myDrive->request_id = $requestId;
$myDrive->email = $data["email"];
$myDrive->name = $data["name"];
if (!$myDrive->save()){
$json["message"] = $this->message->error("Oops! there was a failure creating the drive.")->render();
echo json_encode($json);
return;
}
}catch (Exception $exception){
var_dump($exception);
return;
}
try {
/**
* add user
* reference:https://stackoverflow.com/a/55720522/18215077 | https://developers.google.com/drive/api/v3/reference/permissions
* Role: organizer, fileOrganizer, writer, commenter, reader
*/
$service = $client->ServiceDrive();
$postBody = new Google_Service_Drive_Permission();
$postBody->setKind('drive#permission');
$postBody->setEmailAddress($data["email"]);
$postBody->setType("user");
//$postBody->setRole("organizer"); // Administrador
$postBody->setRole("fileOrganizer");
$optParams = [
'supportsTeamDrives' => true
];
$drive_id = $teamDrive->getId();
try {
$service->permissions->create($drive_id, $postBody, $optParams);
//$service->permissions->create($drive_id, $apiPostBody, $optParams);
} catch (Google_Service_Exception $e) {
//return abort($e->getCode());
var_dump($e->getCode());
}
}catch (Exception $exception){
var_dump($exception);
}
But I don't even know where to start when it comes to removing the user from the team drive, could someone show me some example code.