【问题标题】:Google Drive API Delete PythonGoogle Drive API 删除 Python
【发布时间】:2019-01-10 14:41:24
【问题描述】:

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

更新:我并没有真正尝试代码,只是在寻找一种方法,这就是我没有展示的原因。尽管如此,

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

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

抱歉有任何错误顺便说一句,我在手机上。

【问题讨论】:

  • 您的代码在哪里显示您尝试过的内容?我们不能只是盲目地帮助您...Read this
  • @MikeTung 我在编码中添加了帮助

标签: python python-3.x google-api google-api-python-client google-drive-realtime-api


【解决方案1】:

这段代码没问题。对我来说:

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多