I want to move a file on a shared Google drive into a sub folder, but always getting an error.

Let's say I have folder x and sub_folder x/_old on a shared gdrive.

In folder x I have an abc.png image that I want to move to the x/_old folder.

I first retrieve the file id of that png file as well as the file/folder id of the _old folder:

library(googledrive)
library(tidyverse)
folder_id <- drive_ls(path = "MY_GDRIVE_PATH") |>
  filter(name == "x") |> 
  pull(id)

old_id <- drive_ls(path = folder_id, type = "folder") |>
  filter(name == "_old") |> 
  pull(id)

image_id <- drive_ls(path = folder_id) |> 
  filter(str_detect(name, "abc.png")) |> 
  pull(id)

drive_mv(file = image_id,
         path = old_id,
         overwrite = TRUE)

And I'm getting this error:

Error in `gargle_abort_request_failed()`:
! Client error: (403) Forbidden
A shared drive item must have exactly one parent.
• domain: global
• reason: teamDrivesParentLimit
• message: A shared drive item must have exactly one parent.

Any idea what's going on?

UPDATE:

A workaround by a) copying the file to the _old folder with drive_cp and then removing the original with drive_trash works, which makes me wonder if the drive_mv is a bit too picky here.

1

There are 1 best solutions below

0
On

I fixed this by running drive_auth() and entering '0' to obtain a new token. In the browser, I selected "View, edit and delete all your Google Drive files" option in order to give it permisson.