What's the right way to find files by “full path” in Google Drive API v2

后端 未结 3 1398
后悔当初
后悔当初 2020-12-15 18:22

dear all

I\'m trying to find a list of documents by \"full path\". And after reading the API reference, it seems to be a complex task. Assume my path is something li

相关标签:
3条回答
  • 2020-12-15 19:01

    The biggest problem is that a path does not uniquely identify the file or folder! For example, in the web UI, you can make 2 folders with the same name as children of the same folder. i.e. you can make a tree that looks like: root |-somefolder |-somefolder

    0 讨论(0)
  • 2020-12-15 19:02

    Unlike conventional file systems, a file could be under multiple folders on Drive. Folders are pretty much similar what labels are. Therefore, conventional paths dont always work within our abstraction. I'd suggest you to follow the logic below:

    1. List files with q = 'root' in parents and title = 'path0' and mimeType = 'application/vnd.google-apps.folder' and pick the first result.
    2. If there is a matching result, get the folder's id and perform another listing with '<id of path0>' in parents and title = 'path1' and mimeType='application/vnd.google-apps.folder' and pick the first result.
    3. Keep going until you reach to your target folder.
    0 讨论(0)
  • 2020-12-15 19:19
    1. Search / list with the param q set to name= and include fields param with "files(mimeType,id,name,parents)"
    2. If there is only one search result, return this file
    3. Else if there are multiple files, get the ID in parent and use file's get API with that ID and check if the name matches the last fragment in the path. If only one of the parent Ids match select that option else pick the matching parents and get to check the next parent element in the path

    Essentially check bottom up

    0 讨论(0)
提交回复
热议问题