Skip to content
Advertisement

How can I get breadcrumbs when searching for a file or folder in google drive api?

The situation is as follows: I did a search on google drive, after the search, the found files or folders are displayed. And now, when I go to the found folder, I want to receive data about all other parent folders of this folder with names for navigation on the site. Can you please tell me how can I do this?

I did the search like this:

window.gapi.client.drive.files
  .list({
    q: `name contains '${state.searchFileNameValue}'`,
    fields: 'nextPageToken, files(id, name, size, createdTime, mimeType, webViewLink, parents, sharingUser, webContentLink)'
  })

Advertisement

Answer

You can retrieve the ids of the closest parents of a file by setting fields to files(parents) for the method Files:list or simply parents for the method Files:get

However, this works only for one level – to retrieve the parents of the nesting level above you will need to implement iteration that retrieves the parents of the parents etc. until the response is empty ({}).

Unfortunately there is no way to obtain all parents this in a single request.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement