gpt4 book ai didi

IOS GoogleDrive API - 通过 1 次执行获取子文件夹中的所有文件

转载 作者:行者123 更新时间:2023-11-29 00:50:17 24 4
gpt4 key购买 nike

因此,我尝试使用 Google Drive API 获取文件和文件夹。

- (void)fetchFilesFrom:(NSString *)folderID remoteFolderPath:(NSString *)folderPath {

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = [NSString stringWithFormat:@"'%@' IN parents", folderID]; // get all files and folders under a parent folder
query.fields = @"nextPageToken, files(id, name, mimeType, modifiedTime)"; // get files' and folders' name and id only

[self.serviceDrive executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *fileList,
NSError *error) {
if (error == nil) {
for (GTLDriveFile *file in fileList.files) {
if ([file.mimeType containsString:@"vnd.google-apps.folder"]) { // folder not file
NSString *subFolderPath = [NSString stringWithFormat:@"%@/%@", folderPath, file.name];
[self.driveDict setValue:file forKey:subFolderPath];
// Create the folder locally if not existing
[DocumentHandler checkToCreateDir:subFolderPath];
// Fetch files in a subfolder
[self fetchFilesFrom:file.identifier remoteFolderPath:subFolderPath];
}else if(![file.mimeType containsString:@"vnd.google-apps."]) {
// Ignore other google files like speadsheet... as they are undownloadable
NSString *filePath = [NSString stringWithFormat:@"%@/%@", folderPath, file.name];
[self.driveDict setValue:file forKey:filePath];
}
}

/* If possible, I want to have the full driveDict here in order to compare. */

} else NSLog(@"An error occurred: %@", error);
}];

上面的函数工作正常,但我不想使用递归循环来获取子文件夹中的所有文件。有没有办法只执行1次就获取原始文件夹及其子文件夹中的所有文件?

我提出这个问题的原因是我想在下载驱动器文件之前将远程文件列表与本地文件列表进行比较,以删除不必要的本地文件。使用 executeQuery:completionHandler:^{} block 使我无法成功实现串行执行。 block 内的方法总是稍后执行。

最佳答案

有关更多信息和详细步骤,以下是 Google Drive 官方网站的链接 https://developers.google.com/drive/ios/quickstart

- (void)fetchFiles {
self.output.text = @"Getting files...";
GTLQueryDrive *query =
[GTLQueryDrive queryForFilesList];
//query.pageSize = 10; /* Total number of files to get at once But useful only when there are more than hundreds of file to get once.*/
query.fields = @"nextPageToken, files(id, name)";
[self.service executeQuery:query
delegate:self
didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}

关于IOS GoogleDrive API - 通过 1 次执行获取子文件夹中的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38194052/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com