列出文件的标签

您的组织可以有多个标签,其标签可以有任意数量的字段。本页面介绍如何列出单个 Google 云端硬盘文件上的所有标签。

如需列出文件标签,请使用 files.listLabels 方法。请求正文必须为空。该方法还采用可选的查询参数 maxResults 来设置每页要返回的最大标签数。如果未设置,则返回 100 个结果。

如果成功,响应正文将包含应用于文件的标签列表。这些过滤器位于类型为 Labelitems 对象中。

示例

以下代码示例展示了如何使用标签的 fileId 检索正确的标签。

Java

List<Label> labelList =
labelsDriveClient.files().listLabels("FILE_ID").execute().getItems();

Python

label_list_response = drive_service.files().listLabels(fileId="FILE_ID").execute();

Node.js

/**
* Lists all the labels on a Drive file
* @return{obj} a list of Labels
**/
async function listLabels() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  try {
    const labelListResponse = await service.files.listLabels({
      fileId: 'FILE_ID',
    });
    return labelListResponse;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

FILE_ID 替换为您想要获取标签列表的文件的 fileId