Google Drive API 获取文件元数据

问题描述 投票:0回答:1

有谁知道如何使用 GoggleDrive API 来获取共享驱动器类别中的文件。

我有一个 API 调用,可以用来通过 FileID 获取元数据 适用于与我共享的文件,但当我尝试获取共享云端硬盘上的文件 ID 时,出现错误“找不到文件。”。

请参阅下面的代码及其输出:


def GetFileInfoById(TheFileId):

    service = authenticate()
    # Call the Drive v3 API
    results = service.files().get(fileId=TheFileId,
        fields="id, name, md5Checksum, webViewLink").execute()
    pprint(results)

if __name__ == "__main__":
  GetFileInfoById('  FILE ID Here')

我得到的输出是:

    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting 
https://www.googleapis.com/drive/v3/files/ File ID Here ?fields=id%2C+name%2Cmd5Checksum%2CwebViewLink&
alt=json returned "File not found: 1xJImDFvjIEJlLKUxFqzarm6fSWV8Vlxe.". Details: 
"[{'message': 'File not found: File ID Here.', 'domain': 'global', 'reason': 'notFound', 
'location': 'fileId', 'locationType': 'parameter'}]">

此代码对于我拥有的文件和与我共享的文件按预期工作。我收到一份清单 来自 google API 的文件 ID - 包括我的共享云端硬盘(我在列表调用中使用了 corpora='AllDrives' 参数)。有没有办法将所有驱动器包含在 get 调用中?在我添加参数之前,列表调用并未包含所有内容...

google-drive-api
1个回答
0
投票

如果您尝试通过 Drive API get 方法提取

共享云端硬盘
文件夹中的文件,您可能需要使用
supportsAllDrives
查询参数

supportsAllDrives

boolean
○ 请求应用程序是否支持“我的云端硬盘”和共享云端硬盘。

演示

  • 我通过使用
    supportsAllDrives
    参数在共享驱动器文件夹中提取文件进行了快速测试,它返回了如上所示的文件响应:

enter image description here enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.