【发布时间】:2022-07-22 23:33:29
【问题描述】:
我一直在尝试使用 Google API 在另一个用户与我共享的文件夹上创建文件(我确保我有编辑权限)。当我将 files.create 模块与 supportsAllDrives=True 一起使用时,我收到以下错误消息:
{ "errorMessage": "
https://www.googleapis.com/upload/drive/v3/files?supportsTeamDrives=true&alt=json&uploadType=multipart returned "File not found: 1aLcUoiiI36mbCt7ZzWoHr8RN1nIPlPg7.". 详细信息: "[{'domain': 'global', 'reason': 'notFound', 'message': 'File未找到:1aLcUoiiI36mbCt7ZzWoHr8RN1nIPlPg7.','locationType':'parameter','location':'fileId'}]">", "errorType": "HttpError", "requestId": "fc549b9e-9590-4ab4-8aaa-f5cea87ba4b6", “堆栈跟踪”: [ " 文件 "/var/task/lambda_function.py",第 154 行,在 lambda_handler\n upload_file(service, download_path, file_name, file_name, folder_id, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')\n", " 文件 "/var/task/lambda_function.py",第 78 行,在 upload_file\n file = service.files().create(\n", " 文件 "/opt/python/googleapiclient/_helpers.py",第 131 行,在 positional_wrapper\n 中返回已包装(*args, **kwargs)\n", " 文件 "/opt/python/googleapiclient/http.py",第 937 行,在执行中\n 引发 HttpError(resp, content, uri=self.uri)\n" ] }
经过一番深入研究,我发现“共享驱动器”与“与我共享”不同,到目前为止我发现的所有 API 仅适用于“共享驱动器”。 supportsTeamDrives=True 已被弃用,我无法在文档中找到相关的替换参数。 file.list api 有一个参数sharedWithMe=True,我不确定如何在我的代码中使用它,因为file.create 无论如何都看不到“与我共享”文件夹的文件夹 ID。任何建议都提前表示感谢!
我当前的代码:
def upload_file(service, file_name_with_path, file_name, description, folder_id, mime_type):
media_body = MediaFileUpload(file_name_with_path, mimetype=mime_type)
body = {
'name': file_name,
'title': file_name,
'description': description,
'mimeType': mime_type,
'parents': [folder_id]
}
file = service.files().create(
supportsAllDrives=True,
supportsTeamDrives=True,
body=body,
media_body=media_body).execute()
【问题讨论】:
标签: google-drive-api google-api-python-client google-drive-shared-drive