使用Sheets API v4获取与Google帐户关联的所有电子表格列表

问题描述 投票:6回答:3

使用Google表格API v4,我希望获得附加到我的帐户的电子表格列表。我做了很多研究,但没有找到任何解决方案。

java google-sheets google-spreadsheet-api google-sheets-api
3个回答
7
投票

v4 API不提供列出电子表格的方法。您需要使用Drive API。 Migrate from a previous API page有一些关于如何使用Drive API来执行此操作的详细信息。


3
投票

要获取特定类型的所有文件的列表,可以使用drive API v3。下面是从经过身份验证的用户的驱动器获取所有工作表的示例。

drive.files.list({
    q: "mimeType='application/vnd.google-apps.spreadsheet'",
    fields: 'nextPageToken, files(id, name)'
}, (err, response) => {
    //Your code
})

您可以将MIME类型的文件类型作为“q”参数传递。您可以获取驱动器MIME类型列表here

来源:https://developers.google.com/sheets/api/guides/migration#list_spreadsheets_for_the_authenticated_user


0
投票

为此,您必须使用Drives API。

from apiclient import discovery

credentials = get_credential_service_account()
service = discovery.build('drive', 'v3', credentials=credentials)
service.drive().list()

要获得“凭据”,您可以使用this code

谷歌的官方文件在这里:https://developers.google.com/drive/v3/reference/changes/list

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