如何使用Google Drive API删除Google Drive中的文件?我正在使用v3,实际上我已经尝试了所有方法,但没有任何效果。我相信我尝试过时的方法,目前的方法是什么?

更新:我并不是真的在尝试代码,只是在寻找一种方法,这就是为什么我没有显示。不过,

 service.files().delete(fileId=fileid).execute()


我遇到的错误与服务有关,它没有属性文件。我已经定义了所有其他内容(服务,文件ID),因此得出的结论是它已经过时了。

抱歉,如果有任何错误,我正在使用手机。

最佳答案

这个代码还可以。为了我:

from __future__ import print_function
import os
from apiclient.http import MediaFileUpload
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

SCOPES = 'https://www.googleapis.com/auth/drive'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))

fileDelete='1AKMgCR6v-6uc-JSvhsttBITJzf7k-pDg'
file = DRIVE.files().delete(fileId=fileDelete).execute()

07-24 18:20
查看更多