通过IOS Google Drive SDK列出Google Drive中指定文件夹的所有文件 [英] listing all files from specified folders in Google Drive through IOS Google Drive SDK
问题描述
<强>以下的步骤和将其我使用的代码。强>
首先我得到指定的父文件夹的儿童,然后我得到的 GTLDriveChildReference 的每一个孩子,然后
,则我与孩子参考标识查询。
对我来说,这是一个巨大的过程。它也每次都要求谷歌服务器。 。有没有更好的办法只有通过父文件夹的ID在查询,并从该父文件夹中提取文件
- (空)getFileListFromSpecifiedParentFolder {
GTLQueryDrive * QUERY2 = [GTLQueryDrive queryForChildrenListWithFolderId:其中SOME_ID或根>];
query2.maxResults = 1000;
// queryTicket可用于跟踪请求的状态。
[self.driveService的executeQuery:QUERY2
completionHandler:^(GTLServiceTicket *票,
GTLDriveChildList *儿童,NSError *错误){
的NSLog(@\\\
Google驱动器:文件计入文件夹:%d,children.items.count);
//柜面有这个文件夹下的任何文件,然后我们就可以避开取过程
如果(children.items.count!){
的回报;
}
如果(错误==无){
为(GTLDriveChildReference *孩子的孩子){
GTLQuery *查询= [GTLQueryDrive queryForFilesGetWithFileId: child.identifier];
// queryTicket可用于跟踪请求的状态。
[self.driveService的executeQuery:查询
completionHandler:^(GTLServiceTicket *票,
GTLDriveFile *文件,
NSError *错误){
的NSLog( @\\\
file name =%@,file.originalFilename);
}];
}
}
}];
}
可能被理解任何帮助。
< DIV类= h2_lin>解决方案
尝试在批次查询时,像
GTLBatchQuery * batchQuery = [GTLBatchQuery batchQuery];
为(GTLDriveChildReference *孩子的孩子){
GTLQuery *查询= [GTLQueryDrive queryForFilesGetWithFileId:child.identifier]。
query.completionBlock = ^(GTLServiceTicket *票,GTLDriveFile *文件,NSError *错误){
的NSLog(@ 错误=%@,文件名=%@,错误file.title);
};
[batchQuery addQuery:query];
}
[driveService的executeQuery:batchQuery completionHandler:...]
请求局部也响应快一点和使用更少的存储器,尤其是对大的结果。
看 http日志,以便更好地了解您的查询的响应大小。
Actually i integrated google drive sdk with my ios app. I can able to retrieve/upload the files in google drive through google drive ios sdk. But the retrieving files list from specified parent folder taking so much time.
Here the steps and the code which was i am using.
First am getting the children's of the specified parent folder then am getting the GTLDriveChildReference of each child then then am querying with the child reference identifier.
This is huge process for me. Also it request google server each time. Any better way there to just pass the parent folder id in a query and pulling the files from that parent folder.
-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:<some_id or root>];
query2.maxResults = 1000;
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query2
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveChildList *children, NSError *error) {
NSLog(@"\nGoogle Drive: file count in the folder: %d", children.items.count);
//incase there is no files under this folder then we can avoid the fetching process
if (!children.items.count) {
return ;
}
if (error == nil) {
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
// queryTicket can be used to track the status of the request.
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *file,
NSError *error) {
NSLog(@"\nfile name = %@", file.originalFilename);
}];
}
}
}];
}
Any help that might be appreciated.
Try combining queries in a batch query, like
GTLBatchQuery *batchQuery = [GTLBatchQuery batchQuery];
for (GTLDriveChildReference *child in children) {
GTLQuery *query = [GTLQueryDrive queryForFilesGetWithFileId:child.identifier];
query.completionBlock = ^(GTLServiceTicket *ticket, GTLDriveFile *file, NSError *error) {
NSLog(@"error=%@, file name = %@", error, file.title);
};
[batchQuery addQuery:query];
}
[driveService executeQuery:batchQuery completionHandler:...]
If automatic fetching of result pages is enabled (service.shouldFetchNextPages = YES
) then try to set the maxResults property of queries to avoid the need for the library to make multiple fetches. For example, if there are 100 or fewer results for a query, a maxResults value of 100 will retrieve them with a single fetch.
Requests for partial responses are also a bit faster and use much less memory, particularly for large results.
Look at http logs for a better idea of the response sizes for your queries.
这篇关于通过IOS Google Drive SDK列出Google Drive中指定文件夹的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!