Seamy
Seamy

Reputation: 307

FIle not found error when trying to add parent to file in google drive api

Hi I am getting a 404 file not found error when trying to move a file from one folder to another using google drive api.

I have created a new worksheet using the worksheet api and the response is good containing the new file url and spreadsheet id.

Now I am passing this id to my google drive class. From here I wish to move this file to another folder (so to inherit permissions)

ANyway I am getting a 404 error. I have identified it down to the addParents param on my function returning a 404 error.

 service.files().update(fileId=file_id,
                                  addParents=folder_id,
                                  removeParents=previous_parents,
                                  fields='id, parents').execute()

However when I use the google try it tool it works.

https://developers.google.com/drive/v3/reference/files/get#try-it

I can locate the folder correctly. Am I doing something wrong here? Thanks in advance

Upvotes: 8

Views: 1805

Answers (1)

mlabate
mlabate

Reputation: 61

I've had the same issue. I solved adding supportsAllDrives and supportsTeamDrives parameters.

Something like this:

 service.files().update(fileId=file_id,
                              addParents=folder_id,
                              removeParents=previous_parents,
                              fields='id, parents', 
                              supportsAllDrives=True, 
                              supportsTeamDrives=True).execute()

Upvotes: 6

Related Questions