gpt4 book ai didi

ios - 如何获取文件夹和文件的列表 Google Drive API IOS?

转载 作者:行者123 更新时间:2023-11-29 04:04:03 45 4
gpt4 key购买 nike

我想使用 Google Drive API 从我的 Google Drive 获取所有文件和文件夹名称。

我的查询是这样的:

 GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];

query.q = @"";
//or i also use this code

query.q = @"mimeType = 'text/plain'";

即使我也尝试过这段代码:

-(void)getFileListFromSpecifiedParentFolder {
GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:@"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);
}];
}
}
}];
}

最佳答案

-(void)fetchGoogleDriveFileListWithfolderId:(NSString *)folderId
:(void (^)(NSMutableArray *, NSError*))completionBlock
{
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q =[NSString stringWithFormat:@"'%@' in parents and trashed=false", folderId];

GTLServiceTicket *ticketListing = [self.driveService
executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLDriveFileList *files, NSError *error)
{
NSMutableArray *mainArray=[[NSMutableArray alloc]init];

if (error == nil)
{
completionBlock(files.items,nill);
}
else
{
NSLog(@"An error occurred: %@", error);
completionBlock(nil,error);
}
}];
}

此处 query.q =[NSString stringWithFormat:@"'%@' inParents andrashed=false",folderId];

folderId 可以为“root”(对于根文件夹)、sharedWithMe(对于共享文件夹).如果您想列出已删除的文件,请更改trashed=true。

关于ios - 如何获取文件夹和文件的列表 Google Drive API IOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15476348/

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