C#从Google云端硬盘中的子文件夹ID获取父文件夹名称

时间:2017-01-28 23:27:38

标签: c# google-api google-drive-api

我获得了SubFolder ID,我希望在Google Drive中获取其父文件夹名称。我尝试在Google上搜索很长时间,但没有到达任何地方。我尝试了代码(见下文),但它不起作用。请任何人帮忙吗?

public string GetFolderName(DriveService service, string folderID)
    {
        FilesResource.ListRequest request = service.Files.List();
        request.Q = "'" + folderID + "' mimeType = 'application/vnd.google-apps.folder' and title = 'My_Folder_name'";
        FileList files = request.Execute();
        return files.Items[0].Title;
    }

2 个答案:

答案 0 :(得分:0)

使用https://developers.google.com/drive/v3/reference/files/get获取folderId的元数据。包含fields=parents,它将返回所有子文件夹父项的列表(可能有很多 - 请参阅How do I search sub-folders and sub-sub-folders in Google Drive?)。

一旦您拥有父母的身份证明,就可以使用与fields=name相同的获取来获取他们的姓名。

答案 1 :(得分:0)

尝试使用Parents: list

  

列出文件的父母。

这将返回:

this.userform = this._formbuilder.group({
  email: ['', [Validators.required], [this._validationService.emailExistsValidator.bind(this._validationService)]],
});

获得Parent的fileID后,您现在可以请求获取该文件夹的文件名。如此SO post中所述,父资源不包含fileID的标题,并且必须创建多个请求。

希望这有帮助。

相关问题