2016-05-23 78 views
0

我正在使用Google云端硬盘,而且我的代码使用v3通过服务帐户处理文件。 我可以阅读,下载该文件,但无法删除。 我尝试用v2删除(我没有找到v3删除),没有作品(不是权限)。我试图用V2冒充管理员账号,但没有成功。使用Python删除v3中的文件[服务帐户]

最近,我试图与this link,但没有作品没有范围

def get_credenciales_with_impersonate():  
    delegated_credentials = get_credenciales().create_delegated(admin_email) 
    from httplib2 import Http 
    http_auth = get_credenciales().authorize(Http()) 
    print(type(http_auth)) 
    return http_auth 

...

serviceV2Impersonate = discovery.build('drive','v2',http=get_credenciales_with_impersonate()) 

我正常的凭据是:

def get_credenciales(): 
    credenciales = ServiceAccountCredentials.from_p12_keyfile(
    client_email,p12_file) 
    return credenciales 

和作品

serviceV2 = discovery.build('drive','v2',credentials=credentials) 
serviceV3 = discovery.build('drive','v3',credentials=credentials) 

我该如何使用v3和Python从驱动器中删除文件?

  • 服务帐户[email protected]
  • 其他电子邮件是admin电子邮件
  • 文件的所有者是管理员的电子邮件。我无法更改gserviceaccount和我的域名之间的所有者-differents域名
  • 对不起我的英文不好。

回答

0

在v3中,您必须致电files.update{'trashed':true}

如果您想查找您知道存在的v3功能,请检查Migrate to Google Drive API v3

+0

我想:'高清borrarDeDrive(服务项目): \t尝试: \t \t file_metadata = { \t \t \t '看不上':真 \t \t} \t \t service.files()更新(FILEID =项[ 'ID'], \t \t \t \t \t \t \t \t体= file_metadata).execute(); \t除了错误。HttpError,错误: \t \t print(“没有seo pudo borrar el archivo:%s”%错误)' 并且当请求********返回时,我得到了 HawksGaze

+0

尝试转到您的Google域管理员面板并在安全设置下 - >高级设置 - >管理API客户端访问 将您的客户端ID和范围添加到那里 – Kariamoss

+0

我添加了客户端ID和范围'https:// www。 googleapis.com/auth/drive.file”。我运行的应用程序,我有相同的错误(“用户没有足够的权限这个文件”) – HawksGaze

0

Files: delete为谷歌驱动器REST API V3使用HTTP请求格式:

DELETE https://www.googleapis.com/drive/v3/files/fileId 

但是,请并不表明如果使用所有者的电子邮件是管理员的电子邮件是唯一可能的。

Permanently deletes a file owned by the user without moving it to the trash. If the target is a folder, all descendants owned by the user are also deleted.

而且,由于我们无法文件所有权转让由于不同领域的问题,请尝试本SO后给出的解决方案 - How to delete a google docs without ownership using an API/Services account。我希望它能起作用。

+0

从链接,Python有SignedJwtAssertionCredentials。 Google用http://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html改变了这一点:'def get_credenciales_with_impersonate(): \t f = file(p12_file,'rb') \t key = f。读() \t f.close() \t credenciales = ServiceAccountCredentials.from_p12_keyfile( \t client_email,p12_file,范围= SCOPES) \t返回credenciales.create_delegated(ADMIN_EMAIL)'和\t'serviceV3Impersonate = discovery.build( '驱动' ,'v3',http = get_credenciales_with_impersonate())' 无效(ServiceAccountCrededntials对象没有属性请求) – HawksGaze

相关问题