Php 如何删除文件夹驱动器api
我无法删除文件夹(由其他人创建),即使我尝试更改权限,我有一个控制台应用程序,当前经过身份验证的用户可以执行以下操作:Php 如何删除文件夹驱动器api,php,permissions,google-drive-api,google-api-php-client,Php,Permissions,Google Drive Api,Google Api Php Client,我无法删除文件夹(由其他人创建),即使我尝试更改权限,我有一个控制台应用程序,当前经过身份验证的用户可以执行以下操作: "errors": [ { "domain": "global",
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.appdata',
'https://spreadsheets.google.com/feeds',
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
尝试:
1.为当前用户设置权限
public function deleteFolder(\Google_Service_Drive_DriveFile $folder)
{
$permission = new \Google_Service_Drive_Permission();
$permission->setRole( 'owner' );
$permission->setType( 'user' );
$permission->setEmailAddress('someId@developer.gserviceaccount.com');
$permission = $this->googleDriveClient->permissions->create( $folder->getId(),$permission,array('transferOwnership'=>true));
$this->googleDriveClient->files->delete($folder->getId());
}
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
结果:
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
[谷歌服务例外]{“错误”:{
“错误”:[
{
“域”:“全局”,
“原因”:“内部错误”,
“消息”:“内部错误”
}
],
“代码”:500,
“消息”:“内部错误”}
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
2.将权限类型设置为任何人
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
结果:
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
[谷歌服务例外]{
“错误”:{
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
}
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
尝试3:模拟创建者
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
$this->googleClient->setAccessType('offline');
$this->googleClient->setSubject('x@domain.com');//if removed everything works
[http\Exception\ClientException]客户端错误:
POSThttps://www.googleapis.com/oauth2/v4/token
导致401未经授权的响应:
{
“错误”:“未经授权的客户端”,
“错误描述”:“请求中未经授权的客户端或范围”。,
“错误uri:”
}
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
我丢失了什么吗?只有文件夹的所有者才能删除该文件夹。
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
使用服务帐户,获取文件夹所有者的身份
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }
一旦被授权为文件夹的所有者,就可以删除该文件夹。文件夹中有什么内容吗?您是否删除了其他人的权限?我会坚持使用您的第一个版本,看起来很接近。注意:驱动器权限是一个难题。文件夹为空,我只是尝试添加权限以摆脱它。难题d早期提示:创建权限后列出权限。查看它创建了什么。如果有其他人拥有所有者权限,请删除他们。然后再次列出以确保它确实做到了。然后删除文件夹。(就像拔牙痛一样)嘿,你解决了2吗?我在我的应用程序中遇到了这个问题(@aleXela抱歉,我不能,你可以将它们移动到临时目录并不时删除项目。我工作的项目被推迟,因此我没有进一步调查…我使用的是服务帐户并启用了DWD,文件夹与服务帐户的电子邮件共享(“可编辑”)…我不知道您是否被授权为文件夹的所有者?=>电子邮件地址应该是文件夹的所有者,而不是服务帐户的电子邮件地址。客户端id是否位于g suite的安全面板中,并且具有正确的作用域?项目中是否启用了驱动器api?是否为服务帐户启用了域范围的授权?是所有。。。附言:我有一个python脚本,它可以做与我想做的完全相同的事情,但是现在我想将它“翻译”成PHP以便于维护(所有凭证和设置都被复制)。这很烦人,我不能删除空文件夹,但可以创建文件和文件夹等。唯一的区别是,要删除文件夹,您需要是文件夹的所有者。这就是我建议使用服务帐户的原因。我仍然怀疑域范围的委派,这是云控制台项目中服务帐户上的一个单独复选框.100%确定已检查?
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for this file ."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for this file." }