尝试获取文件元数据时出现错误404

时间:2019-08-31 22:53:21

标签: google-drive-api

尝试通过Google Drive Api files.get方法访问文件元数据时出现404错误。

我尝试使用相同的用户和相同的fileID从Api测试页重现该错误:https://developers.google.com/drive/api/v3/reference/files/get 但是我无法重现该错误。在此页面上,我得到200的响应,并得到所需的元数据(文件名等)。这意味着FileID正确且文件确实存在

Google认为404错误可能是由于权限不足所致(我认为情况并非如此,在我的代码中,我使用的是https://www.googleapis.com/auth/drive,据我所知包括对元数据的访问)。否则文件不存在,情况也不是如此。

我不知道还能尝试什么。这是我简单的Python代码:

#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()

错误:

https://www.googleapis.com/drive/v3/files/%5B%271uP0WhJXtjHBSnBb4KS80GexG9P5OLH-p%27%5D?alt=json返回“找不到文件:['1uP0WhJXtjHBSnBb4KS80GexG9P5OLH-“>”。 / p>

1 个答案:

答案 0 :(得分:0)

好,我发现了问题。

item.get('parents',[0])不是返回字符串,而是列表。

我将其替换为item ['parents'] [0],现在可以正常使用了。