2016-05-23 77 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

相關問題