所以我试图使用Google Drive API获取文件和文件夹。IOS GoogleDrive API - 获取1个执行子文件夹中的所有文件
- (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);
}];
}
上述功能工作正常,但我不希望使用递归循环来获得子文件夹中的所有文件。有没有办法让原始文件及其子文件夹中的所有文件只有一次执行?
我把它带来的原因是我想比较远程文件列表与本地文件列表以删除不必要的本地文件,然后再下载驱动器文件。并且使用executeQuery:completionHandler:^{}
块使我无法成功实现串行执行。块内的方法总是在稍后执行。
虽然此链接可以回答这个问题,这是更好地在这里包含答案的重要部分并提供链接供参考。如果链接页面更改,则仅链接答案可能会失效。 – Marusyk
在发布我的问题之前,我实际上多次阅读本教程。 – Tim
您可以查看我再次转贴的答案。请让我你需要详细的帮助。我可以一步一步地引导你。 –