0

I have integrated google drive api using GCP service account to fetch the files, when iam searching any keyword inside a parent folder its giving accurate results but when the search is happening inside child folder results are not matching with google drive search results. I have tried for

corpora:'allDrives',
includeTeamDriveItemsRequired:true,
includeItemsFromAllDrives:true,
supportsAllDrives:true,

below is my code

const driveRes = await driveService.files.list({
            q: "trashed=false and ('1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8' in parents ) and fullText contains 'analytical'",
            fields: 'nextPageToken, files(id, name, mimeType, parents, createdTime, modifiedTime, thumbnailLink)',
            spaces: 'drive',
            pageSize: pageSize,
            pageToken: pageToken,

        });
        console.log('get-drive-files-impl.searchFileFolderWithContent: ', driveRes.data.files.length); // THIS GIVES 6

Drive search Result

Actual search result in drive

  1. Any solutions for this, or am I missing anything

-- Edit

My folder ID structure in hierarchical way is

parent folder(1uEO8c63iPtYeP-_mALtff0yKtQb7GY2R) -> 
         (1. child folder)1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8 -- 
                - File A
                - File B
                - File C
         (2. child folder)1JFfSP6TDoEzNC7v_ULuWR9LHC9Yaau7s -- 
                - File A

Strange thing is for this query i.e. searching from root folder via recursive parent search below.

trashed=false and ('1uEO8c63iPtYeP-_mALtff0yKtQb7GY2R' in parents or '1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8' in parents or '1JFfSP6TDoEzNC7v_ULuWR9LHC9Yaau7s' in parents) and fullText contains 'analytical'

It gives proper results.

But

trashed=false and '1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8' in parents and fullText contains 'analytical'

Gives incorrect result

Anuroop S
  • 91
  • 9
  • About `I have integrated google drive api using GCP service account to fetch the files`, in your situation, is the folder of `1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8` shared with the service account? Or, your service account can access the folder? I'm worried about it because I couldn't understand it from your question. I apologize for this. – Tanaike Aug 25 '23 at 12:01
  • Um your using a service account right? Why are you looking in the web app? A service account doesn't have access to the web app. or did you grant it access to that folder you must have or i would have expected an error message. – Linda Lawton - DaImTo Aug 25 '23 at 12:04
  • @Tanaike I have given folder access to the service account. 1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8 folder is shared with service account using client email. Strange thing is going one level up and searching using the same search term it gives the result – Anuroop S Aug 25 '23 at 12:10
  • @LindaLawton-DaImTo Yes I have given folder access to the service account, hence no errors – Anuroop S Aug 25 '23 at 12:11
  • Thank you for replying. From your reply, I understood that the target folder has already been shared with the service account. But, I have to apologize for my poor English skill. Unfortunately, I cannot understand `Strange thing is going one level up and searching using the same search term it gives the result`. Can I ask you about the details of it? – Tanaike Aug 25 '23 at 12:23
  • @Tanaike I have added more details in question. Apologies if I confused you. – Anuroop S Aug 25 '23 at 12:41
  • Thank you for replying. Can I ask you about the details of the relationship between "My folder structure is" and your search query? For example, `Parent A` and `Parent B` are `'folder ID of parent A' in parents or 'folder ID of parent B' in parents,,,` and those folders have already been shared with the email of the service account. Is my understanding correct? – Tanaike Aug 25 '23 at 12:44
  • It supposes that "My folder" is Google Drive of your Google account. If my understanding is correct, how about the following method? 1. Create a new folder with your Google account and share it with the email of the service account. 2. Move all folders of `Parent A`, `Parent B` and so on to the new folder. 3. Retrieve the file list with a search query like `'folder ID of new folder' in parents` for searching a top folder? If this is not included in your expected result, I apologize. – Tanaike Aug 25 '23 at 12:48
  • And, if you want to retrieve the file list including the subfolders, this thread and a library might be able to be used. https://stackoverflow.com/q/66523335 and https://github.com/tanaikech/node-getfilelist But, if this was not included in your expected direction, I apologize. – Tanaike Aug 25 '23 at 12:50
  • @Tanaike I have remodified the folder structure with the folder ids. Hope this will resolve the confusion. – Anuroop S Aug 25 '23 at 13:00
  • Thank you for replying. Can I ask you about the detali of `Gives incorrect result`? In the case of `trashed=false and '1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8' in parents and fullText contains 'analytical'`, I think that the files under `1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8` are searched. How about this? – Tanaike Aug 25 '23 at 23:53
  • @Tanaike When i do drive search for the word "analytical" inside the folder id "1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8" it gives 8 files but if i do the same search using google drive API for the folder id "1QLOnVfHvt_M6P8PGTI5z58IjcYXnIFD8" it gives 6 files so this is why i said it gives incorrect result. – Anuroop S Aug 28 '23 at 05:15
  • Thank you for replying. From your reply, when I could correctly replicate your situation, I would like to think of the reason for the issue and a solution. – Tanaike Aug 28 '23 at 05:44

0 Answers0