Using the following method, I am able to get the sub-folders, but this code retrieves all the folders from the root. For example, if there is a folder in trash also it retrieves that along with folders in My Drive.

My requirement is that, if the folder is not there in the My Drive, then first I should create one and then insert files. My problem is, when I am checking for the folder name, as the folder exist in trash but not in My Drive, I am getting response as folder exists.

Here is my method to retrieve folders.

If anyone has some idea, please let me know.

-(void)getFileListFromSpecifiedParentFolder {
    GTLQueryDrive *query2 = [GTLQueryDrive queryForFilesList];
//    GTLQueryDrive *query2 = [GTLQueryDrive queryForChildrenListWithFolderId:@"My Drive"];

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

    query2.q = @"mimeType = 'application/vnd.google-apps.folder'";

    // 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 = %@ \n file kind %@ \n file identifier %@", file.title,file.kind,file.identifier);
                                            }];
                          }
                      }
                      else
                          [self createFolderForGoogleDriveWithName:@"Music"];
                  }];
}
有帮助吗?

解决方案

You can filter out trashed directories with the following query: application/vnd.google-apps.folder' and trashed = false

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top