我试图用Python从googledriveapiv3检索文件元数据。我在API V2中做过,但在V3中失败了。 我试图通过这行代码获取元数据:
data = DRIVE.files().get(fileId=file['id']).execute()
但我得到的只是'id'
、'kind'
、'name'
、和{'md5Checksum'
,'fileSize'
,等等?在
我读了documentation。
我应该通过get()
方法获得所有元数据,但我得到的只是其中的一小部分。在
这是我的代码:
^{pr2}$我试着回答: Google Drive API v3 Migration
List
Files returned by
service.files().list()
do not contain information now, i.e. every field is null. If you want list on v3 to behave like in v2, call it like this:service.files().list().setFields("nextPageToken, files");
但我得到了回溯:
DRIVE.files().list().setFields("nextPageToken, files")
AttributeError: 'HttpRequest' object has no attribute 'setFields'
如果要检索文件资源的所有字段,只需设置
fields='*'
在上面的示例中,您将运行
这将返回文件的所有可用资源,如中所示: https://developers.google.com/drive/v3/reference/files
假设您想获得给定文件
fileId
的md5哈希,可以这样做:要列出驱动器上的一些文件:
^{pr2}$我已经构建了一个小应用程序gDrive-auto-sync,其中包含更多的API用法示例。
它有很好的文档记录,所以如果你想看一看。
Here是包含所有代码的主文件。它看起来可能很多,但超过一半的行只是注释。在
有一个库PyDrive提供了与googledrive的简单交互
https://googledrive.github.io/PyDrive/docs/build/html/filelist.html
他们的例子:
你只需要
file1['your key']
相关问题 更多 >
编程相关推荐