我想从文件夹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错误。
如何做到这一点?
您需要重构代码的逻辑。
'parentFolderId' in parents and mimeType='application/vnd.google-apps.folder'
并将其设置Fields
为files/id
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句