Clement Bjelland
Clement Bjelland

Reputation: 11

Error 404 when trying to get file metadata

I am getting a 404 error when trying to access a file metadata with Google Drive Api, files.get method.

I've tried to reproduce the error using the same user and the same fileID, from the Api test page: https://developers.google.com/drive/api/v3/reference/files/get But I can't reproduce the error. From this page I get a 200 response and I get the metadata I need (file name, etc.) That means the FileID is correct and the file does exist

According to Google the 404 error can be due to insufficient permissions (I don't think this is the case, in my code I am using https://www.googleapis.com/auth/drive which I understand includes access to metadata). Or else the file does not exist, which is also not the case.

I don't know what else to try. Here's my simple Python code:

#GET THE FILES LIST - THIS WORKS PERFECTLY:
theFiles = drive_service.files().list(pageSize=1000,q="trashed=false and mimeType != 'application/vnd.google-apps.folder'",orderBy="quotaBytesUsed desc, name, modifiedTime desc",fields="files(id,name,modifiedTime,quotaBytesUsed,starred,webViewLink, parents)").execute()
dicFiles = theFiles.get('files',[])

#GET METADATA
for item in dicFiles:
    parentID=item.get('parents',[0])

    #HERE I GET THE 404 ERROR
    metadata= drive_service.files().get(fileId=parentID).execute()

Error:

https://www.googleapis.com/drive/v3/files/%5B%271uP0WhJXtjHBSnBb4KS80GexG9P5OLH-p%27%5D?alt=json returned "File not found: ['1uP0WhJXtjHBSnBb4KS80GexG9P5OLH-p'].">

Upvotes: 0

Views: 950

Answers (1)

Clement Bjelland
Clement Bjelland

Reputation: 11

Ok, I found the problem.

item.get('parents',[0]) wasn't returning a string, but a list.

I replaced that by item['parents'][0] and now it's working.

Upvotes: 0

Related Questions