Google drive api 如果存在同名对象,Google Drive API v3将更新该对象:list';q';参数不按文档所述工作?

Google drive api 如果存在同名对象,Google Drive API v3将更新该对象:list';q';参数不按文档所述工作?,google-drive-api,google-drive-shared-drive,Google Drive Api,Google Drive Shared Drive,如果某个文件存在于特定文件夹中且具有特定名称,我将尝试更新该文件。在本例中,所讨论的对象位于团队驱动中。我按照文档将q参数组合到list调用中,尝试切换回v2…似乎查询的组合完全正确。也就是说,即使我看到目标文件夹中存在多个对象,列表调用也无法看到它们。我尝试了name='和name包含'。谷歌团队似乎已经准备好了足够的输入验证,就像我开始创作API炸弹一样。有什么建议吗 def import_or_replace_csv_to_td_folder(self, folder_id, local_

如果某个文件存在于特定文件夹中且具有特定名称,我将尝试更新该文件。在本例中,所讨论的对象位于团队驱动中。我按照文档将
q
参数组合到
list
调用中,尝试切换回v2…似乎查询的组合完全正确。也就是说,即使我看到目标文件夹中存在多个对象,列表调用也无法看到它们。我尝试了
name='
name包含'
。谷歌团队似乎已经准备好了足够的输入验证,就像我开始创作API炸弹一样。有什么建议吗

def import_or_replace_csv_to_td_folder(self, folder_id, local_fn, remote_fn, mime_type):
    DRIVE = build('drive', 'v3', http=creds.authorize(Http()))
    query = "'{0}' in parents and name = '{1}'.format(folder_id, remote_fn)
    print("Searching for previous versions of this file : {0}".format(query))
    check_if_already_exists = DRIVE.files().list(q=query, fields="files(id, name)").execute()
    name_and_location_conflict = check_if_already_exists.get('files', [])
    if not name_and_location_conflict:
        body = {'name': remote_fn, 'mimeType': mime_type, 'parents': [folder_id]}
        out = DRIVE.files().create(body=body, media_body=local_fn, supportsTeamDrives=True, fields='id').execute().get('id')
        return out
    else:
        if len(name_and_location_conflict)==1:
            file_id=name_and_location_conflict['id']
            DRIVE.files().update(fileId=file_id, supportsTeamDrives=True, media_body=local_fn)
            return file_id
        else:
            raise MultipleConflictsError("There are multiple documents matching parent folder and file name. Unclear which requires a version update")
当我试图将'name'参数替换为'title'时(根据我回顾的一些答案,在v2中使用),API发出了barfed

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?q=%27xxxxxxxxxxxxxxxx%27+in+parents+and+title+%3D+%27Somefile_2018-09-27.csv%27&fields=files%28id%2C+name%29&alt=json returned "Invalid Value">
googleapiclient.errors.HttpError:
谢谢@tehhowch

事实上,当需要设置团队驱动中的目标(即includeTeamDriveItems选项)时,需要额外的措施,否则默认情况下不包括TD位置:

   check_if_already_exists = DRIVE.files().list(
       q=query, 
       fields="files(id, name)",
       supportsTeamDrives=True,
       includeTeamDriveItems=True
   ).execute()

查看有关使用团队驱动项目的驱动API文档。你必须采取额外的措施。