列出目录中ID不是Google Drive API v3和C#中特定值的文件夹

蛇眼

我想从文件夹ID中获取子文件夹列表,但要通过特定ID(并非全部)获得子文件夹的列表。我的意思是我想让孩子获得ID不在我提供的列表中

 public async Task<FileListData> ListWithoutIds(string id, int itemsPerPage = 10, string nextPageToken = null, bool onlyFolders = false, bool onlyFiles = false, string[] excludeIds = null)
{
  if (string.IsNullOrWhiteSpace(id))
  {
    throw new ArgumentException($"'{nameof(id)}' cannot be null or whitespace", nameof(id));
  }

  var request = PrepareListRequest(itemsPerPage, nextPageToken);
  request.Q = $"'{id}' in parents";
  if (onlyFolders)
  {
    request.Q = $"{request.Q} and mimeType='application/vnd.google-apps.folder'";
  }
  else if (onlyFiles)
  {
    request.Q = $"{request.Q} and not mimeType='application/vnd.google-apps.folder'";
  }

  if (excludeIds?.Length > 0)
  {
    request.Q = $"{request.Q} {string.Join(" ", excludeIds.Select(e => $"and not id='{e}'"))}";
  }

  return FileListData.From(await request.ExecuteAsync()); // here I got 400 error
}

private FilesResource.ListRequest PrepareListRequest(int itemsPerPage, string nextPageToken, string[] specificFields = null)
{
  var request = driveService.Files.List();
  request.PageSize = itemsPerPage;
  request.SupportsAllDrives = true;
  request.IncludeItemsFromAllDrives = true;

  if (!string.IsNullOrWhiteSpace(nextPageToken))
  {
    request.PageToken = nextPageToken;
  }

  if (specificFields?.Length > 0)
  {
    var fields = $"{string.Join(",", specificFields)}";
    request.Fields = $"nextPageToken, files({fields.Trim(',')})";
  }
  else
  {
    request.Fields = "nextPageToken, files";
  }
  return request;
}

执行的查询如下所示:

'parentFolderId' in parents and mimeType='application/vnd.google-apps.folder' and not id='Child1Id' and not id='Child2Id' and not id='Child3Id'

我得到了400错误。

如何做到这一点?

日加诺奇卡

Drive API的查询功能非常有限,列表结果的ID不可能是查询字词

您需要重构代码的逻辑。

  • 首先使用查询获取您的文件夹列表,'parentFolderId' in parents and mimeType='application/vnd.google-apps.folder'并将其设置Fieldsfiles/id
  • 随后以编程方式实现一个过滤器,以从总ID列表中减去您要排除的ID。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Google Drive API v3 PHP中的特定文件夹中列出文件

Google Drive API v3在Java中获取根文件夹ID

列出用户在 Google Drive V3 API 中具有写入权限的所有文件夹

如何在根目录中创建文件夹并在Android的Google Drive REST API v3中获取其ID

Google Drive API V2 / V3中小于登录的文件夹名称

是否可以使用Google Drive API列出Google Drive中指定目录中的文件?

如何使用 Google Drive API v3 将可恢复上传到 Python 中的共享文件夹?

Google Drive API v3(C#.NET)按标题搜索文件夹/文件会引发RequestError无效值[400]

在C#中的Google Drive Api v3中获取根ID

如何使用 Google Drive API Javascript 列出特定文件夹中的更改

如何在分页和使用排序依据时列出Google Drive API v3上的所有根文件夹和共享?

列出 Google Drive API 中的活动频道

如何在C#中列出来自Google Drive API V3的1000多个记录

Google Drive API 不再用于列出文件夹中的文件

使用python,我无法从Google Drive API v3访问共享驱动器文件夹

使用Google Drive API上传文件夹中的文件

如何让 Google Drive API v3 示例在 C# 中工作?

如何使用 Python 和 Drive API v3 从 Google Drive 下载文件

如何在 google drive api 中复制文件夹?

通过 API 重命名 Google Drive 中的文件夹

Google Drive API搜索文件夹

Google DRIVE API V3-使用nodejs获取根文件夹ID

文件夹中的文件列表/ DRIVE API PyDRIVE

通过Drive API访问文件夹中的文件?

文件夹中的文件列表/ DRIVE API PyDRIVE

选择特定字段Google Drive API v3

如何使用Google Drive API和Python将文件上传到特定文件夹?

Drive API v3,C# - 文件夹层次结构

如何使用Google的Python Drive Client API在Team Drive中创建文件夹?