tidyverse/googledrive

Listing files in a google drive folder

IsabelFoodsteps opened this issue · 2 comments

I'm using a service account to access folders/files in a Shared Drive (ID: "xyz"). I'm not able to give whole drive access to the service account, but can apply Content Manager permissions at various directory/individual file levels.

I have a folder (ID: "abc") on which the service account has Content Manager permission.

googledrive::drive_get(googledrive::as_id("abc")) returns a dribble with the folder name/ID. However, I hit the following issues upon trying to list the contents of the folder using drive_ls:

Attempted

googledrive::drive_ls(path = googledrive::as_id("abc"))
googledrive::drive_ls(path = googledrive::as_dribble(googledrive::as_id("abc")))

Error

Error in `gargle::response_process()`:
! Client error: (404) Not Found
Shared drive not found: xyz
• message: Shared drive not found: xyz
• domain: global
• reason: notFound
• location: driveId
• locationType: parameter

Is this a limitation of drive_ls, or should I be using some additional parameters related to the Shared Drive? Many thanks!

I think you should experiment with providing shared_drive and/or corpus, i.e. some of the ... parameters.

I just worked on an issue with recursively listing a folder that is on a shared drive and thus I've gotten re-acquainted with this situation.

In your case, I think the problem is just that you aren't following this part of the drive_ls() docs:

If it is a shared drive or is a folder on a shared drive, it must be passed as a dribble.

You seem to be passing the folder's ID. But you need to get the folder first in dribble form and then pass that. This is because a dribble contains the full metadata on the file (folder, in this case), including the info about the shared drive, in the drive_resource list-column.

Here's an example that works for me:

library(googledrive) 

shared_drive <- shared_drive_find("NAME_OF_THE_SHARED_DRIVE")
target_folder <- drive_find("NAME_OF_THE_FOLDER", type = "folder", shared_drive = shared_drive)
target_folder # notice that this is a dribble!
#> # A dribble: 1 × 3
#>   name               id                                drive_resource   
#>   <chr>              <drv_id>                          <list>           
#> 1 NAME_OF_THE_FOLDER 1vJvF58MOTcKrWYNPEz8KYf7Rglx1KA6D <named list [31]>
drive_ls(target_folder)