返回用户信息
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google 云端硬盘提供了两种收集云端硬盘用户相关信息的方式:
本指南介绍了如何在云端硬盘中检索用户信息。
获取用户的详细信息
如需以 about
的实例形式返回有关云端硬盘用户的信息,请使用 get
方法。返回的值以字节为单位。
您必须在 get
方法中设置 fields
系统参数,以指定要在响应中返回的字段。在大多数 Drive 方法中,此操作仅在需要返回非默认字段时才需要,但对于 about
资源,此操作是强制性的。如果省略此参数,该方法会返回错误。如需了解详情,请参阅返回特定字段。
以下代码示例展示了如何在请求中以查询参数的形式提供多个 fields
。响应会返回请求的字段值。
请求
GET https://www.googleapis.com/drive/v3/about/?fields=kind,user,storageQuota
答案
{
"kind": "drive#about",
"user": {
"kind": "drive#user",
"displayName": "DISPLAY_NAME",
"photoLink": "PHOTO_LINK",
"me": true,
"permissionId": "PERMISSION_ID",
"emailAddress": "EMAIL_ADDRESS"
},
"storageQuota": {
"usage": "10845031958",
"usageInDrive": "2222008387",
"usageInDriveTrash": "91566"
}
}
响应包含以下值:
DISPLAY_NAME
:用户的纯文本名称。
PHOTO_LINK
:用户个人资料照片的网址。
PERMISSION_ID
:Permission
资源中的用户 ID。
EMAIL_ADDRESS
:用户的电子邮件地址
列出用户应用
Google 云端硬盘应用会在 Google Workspace Marketplace 中列出,用于让云端硬盘更方便易用,例如 Google 文档应用或在 Google 文档中用于签署文档的插件。如需了解详情,请参阅使用 Google 云端硬盘应用。
如需返回用户安装的所有应用的列表(以 apps
的实例形式),请使用不带任何参数的 list
方法。
如果您想指定要在响应中返回的字段,可以设置 fields
system 参数。如果您未指定 fields
参数,服务器会返回一组默认字段。如需了解详情,请参阅返回特定字段。
以下代码示例展示了如何在请求中返回用户已安装的所有应用的列表。响应会返回请求的字段值。
请求
GET https://www.googleapis.com/drive/v3/apps
答案
{
"kind": "drive#appList",
"selfLink": "https://www.googleapis.com/drive/v3/apps",
"items": [
{
"kind": "drive#app",
"id": "ID",
"name": "Google Sheets",
"supportsCreate": true,
"supportsImport": true,
"supportsMultiOpen": false,
"supportsOfflineCreate": true,
"productUrl": "https://chrome.google.com/webstore/detail/felcaaldnbdncclmgdcncolpebgiejap",
"productId": "PRODUCT_ID"
}
],
"defaultAppIds": [
"ID"
]
}
响应包含以下值:
ID
:应用 ID。
PRODUCT_ID
:相应应用的商品详情 ID。
使用查询参数列出用户应用
如需查找特定应用,请使用一个或多个可选查询参数:
appFilterExtensions
:使用英文逗号分隔的文件扩展名列表过滤搜索结果。应用查询范围内的可打开所列文件扩展名的应用会包含在响应中。如果还提供了 appFilterMimeTypes
,则返回这两个应用列表的并集。
扩展程序的示例包括 Microsoft Word 的 docx
和 Microsoft PowerPoint 的 pptx
。如需查看更多文件扩展名示例,请参阅 Google Workspace 文档的导出 MIME 类型。
以下代码示例展示了如何以查询参数的形式提供多个文件扩展名:GET
https://www.googleapis.com/drive/v3/apps?appFilterExtensions=docx,pptx
。
appFilterMimeTypes
:使用以英文逗号分隔的 MIME 类型列表过滤搜索结果。应用查询范围内的可打开所列 MIME 类型的应用会包含在响应中。如果还提供了 appFilterExtensions
,则返回这两个生成的应用列表的并集。MIME 类型的示例包括 Google 表单的 application/vnd.google-apps.form
和 Google 协作平台的 application/vnd.google-apps.site
。如需查看更多 MIME 类型示例,请参阅 Google Workspace 和 Google 云端硬盘支持的 MIME 类型。
以下代码示例展示了如何以查询参数的形式提供多个 MIME 类型:GET
https://www.googleapis.com/drive/v3/apps?appFilterMimeTypes=application/vnd.google-apps.form,application/vnd.google-apps.site
。
languageCode
:使用 BCP 47 定义的语言或语言区域代码(带有一些来自 Unicode 的 LDML 格式的扩展)过滤搜索结果。语言代码示例包括 en-us
(英语 [美国])和 fr-ca
(法语 [加拿大])。
以下代码示例展示了如何以查询参数的形式提供多个语言代码:GET
https://www.googleapis.com/drive/v3/apps?languageCode=en-us,fr-ca
。
根据 ID 获取用户应用
如需下载详细的应用信息作为 apps
的实例,请使用 get
方法并提供应用 ID。
以下代码示例展示了如何在请求中以查询参数的形式提供 appId
。响应会返回请求的字段值。
请求
GET https://www.googleapis.com/drive/v3/apps/APP_ID
答案
{
"kind": "drive#app",
"id": "ID",
"name": "Google Sheets",
"supportsCreate": true,
"supportsImport": true,
"supportsMultiOpen": false,
"supportsOfflineCreate": true,
"productUrl": "https://chrome.google.com/webstore/detail/felcaaldnbdncclmgdcncolpebgiejap",
"productId": "PRODUCT_ID"
}
响应包含以下值:
ID
:应用 ID。
PRODUCT_ID
:相应应用的商品详情 ID。
您可以尝试以下几个后续步骤:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-01。
[null,null,["最后更新时间 (UTC):2025-09-01。"],[],[],null,["Google Drive provides two options to gather information about\nDrive users:\n\n- Using the [`about`](/workspace/drive/api/reference/rest/v3/about) resource, you can retrieve\n information about the user, the user's Drive settings, and\n their system capabilities.\n\n- Using the [`apps`](/workspace/drive/api/reference/rest/v3/apps) resource, you can retrieve a\n list of the user's installed apps, with information about each app's\n supported MIME types, file extensions, and other details.\n\nThis guide explains how you can retrieve user info in Drive.\n\nGet details about a user\n\nTo return information on a Drive user as an instance of\n[`about`](/workspace/drive/api/reference/rest/v3/about), use the\n[`get`](/workspace/drive/api/reference/rest/v3/about/get) method. The returned values are measured\nin bytes.\n\nYou *must* set the `fields` [system\nparameter](https://cloud.google.com/apis/docs/system-parameters#definitions) on\nthe `get` method to specify the fields to return in the response. In most\nDrive methods this action is only required to return non-default\nfields but it's mandatory for the `about` resource. If you omit the parameter,\nthe method returns an error. For more information, see [Return specific fields](/workspace/drive/api/guides/fields-parameter).\n| **Note:** If you're using the previous Drive API v2 version, setting the `fields` parameter in the `get` method isn't required. Learn how to [migrate to\nDrive API v3](/workspace/drive/api/guides/migrate-to-v3). \nThe following code sample shows how to provide multiple `fields` as a query parameter in the request. The response returns the field values for the request.\n\n**Request** \n\n```text\nGET https://www.googleapis.com/drive/v3/about/?fields=kind,user,storageQuota\n```\n\n**Response** \n\n```scdoc\n{\n \"kind\": \"drive#about\",\n \"user\": {\n \"kind": \"drive#user\",\n \"displayName\": \"DISPLAY_NAME\",\n \"photoLink\": \"PHOTO_LINK\";,\n \"me\": true,\n \"permissionId\": \"PERMISSION_ID\",\n \"emailAddress\": \"EMAIL_ADDRESS\"\n },\n \"storageQuota\": {\n \"usage\": \"10845031958\",\n \"usageInDrive\": \"2222008387\",\n \"usageInDriveTrash\": \"91566\"\n }\n}\n```\n\nThe response includes the following values:\n\n- \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e: the user's name in plain text.\n- \u003cvar translate=\"no\"\u003ePHOTO_LINK\u003c/var\u003e: the URL of the user's profile photo.\n- \u003cvar translate=\"no\"\u003ePERMISSION_ID\u003c/var\u003e: the user's ID within the `Permission` resources.\n- \u003cvar translate=\"no\"\u003eEMAIL_ADDRESS\u003c/var\u003e: the user's email address\n\nList user apps\n\nGoogle Drive apps are listed in the\n[Google Workspace Marketplace](https://workspace.google.com/marketplace) and\nare used to make Drive more convenient such as the Google Docs\napp or an add-on used within Docs to\nsign documents. For more information, see [Use Google Drive\napps](https://support.google.com/drive/answer/2500820).\n\nTo return a list of all the user's installed apps as an instance of [`apps`](/workspace/drive/api/reference/rest/v3/apps), use the [`list`](/workspace/drive/api/reference/rest/v3/apps/list) method\nwithout any parameters.\n\nIf you want to specify the fields to return in the response, you can set the\n`fields` [system\nparameter](https://cloud.google.com/apis/docs/system-parameters#definitions). If\nyou don't specify the `fields` parameter, the server returns a default set of\nfields. For more information, see [Return specific fields](/workspace/drive/api/guides/fields-parameter).\n| **Note:** If you're using the previous Drive API v2 version, the response body also includes the `etag` field. Learn how to [migrate to\nDrive API v3](/workspace/drive/api/guides/migrate-to-v3). \nThe following code sample shows how to return a list of all the user's installed apps in the request. The response returns the field values for the request.\n\n**Request** \n\n```text\nGET https://www.googleapis.com/drive/v3/apps\n```\n\n**Response** \n\n```scdoc\n{\n \"kind\": \"drive#appList\",\n \"selfLink\": \"https://www.googleapis.com/drive/v3/apps\",\n \"items\": [\n {\n \"kind\": \"drive#app\",\n \"id\": \"ID\",\n \"name\": \"Google Sheets\",\n \"supportsCreate\": true,\n \"supportsImport\": true,\n \"supportsMultiOpen\": false,\n \"supportsOfflineCreate\": true,\n \"productUrl\": \"https://chrome.google.com/webstore/detail/felcaaldnbdncclmgdcncolpebgiejap\",\n \"productId\": \"PRODUCT_ID\"\n }\n ],\n \"defaultAppIds\": [\n \"ID\"\n ]\n}\n```\n\nThe response includes the following values:\n\n- \u003cvar translate=\"no\"\u003eID\u003c/var\u003e: the app ID.\n- \u003cvar translate=\"no\"\u003ePRODUCT_ID\u003c/var\u003e: the product listing ID for this app.\n\nList user apps with query parameters\n\nTo find a specific app, use one or more of the optional query parameters:\n\n- `appFilterExtensions`: Filter the search results using a comma-separated\n list of file extensions. Apps within the app query scope that can open the\n listed file extensions are included in the response. If `appFilterMimeTypes`\n are also provided, a union of the two resulting app lists is returned.\n Examples of extensions include `docx` for Microsoft Word and `pptx` for\n Microsoft PowerPoint. For more examples of file extensions, see [Export MIME\n types for Google Workspace documents](/workspace/drive/api/guides/ref-export-formats).\n\n The following code sample shows how to provide multiple file extensions as a\n query parameter: `GET\n https://www.googleapis.com/drive/v3/apps?appFilterExtensions=docx,pptx`.\n- `appFilterMimeTypes`: Filter the search results using a comma-separated list\n of MIME types. Apps within the app query scope that can open the listed MIME\n types are included in the response. If `appFilterExtensions` are also\n provided, a union of the two resulting app lists is returned. Examples of\n MIME types include `application/vnd.google-apps.form` for Google Forms and\n `application/vnd.google-apps.site` for Google Sites. For more examples of\n MIME types, see [Google Workspace and Google Drive supported MIME\n types](/workspace/drive/api/guides/mime-types).\n\n The following code sample shows how to provide multiple MIME types as a\n query parameter: `GET\n https://www.googleapis.com/drive/v3/apps?appFilterMimeTypes=application/vnd.google-apps.form,application/vnd.google-apps.site`.\n- `languageCode`: Filter the search results using a language or locale code,\n as defined by BCP 47, with some extensions from [Unicode's LDML\n format](https://www.unicode.org/reports/tr35/). Examples of language codes\n include `en-us` for English (United States) and `fr-ca` for French (Canada).\n\n The following code sample shows how to provide multiple language codes as a\n query parameter: `GET\n https://www.googleapis.com/drive/v3/apps?languageCode=en-us,fr-ca`.\n\nGet user app by ID\n\nTo download the detailed app info as an instance of\n[`apps`](/workspace/drive/api/reference/rest/v3/apps), use the [`get`](/workspace/drive/api/reference/rest/v3/apps/get)\nmethod with the app ID. \nThe following code sample shows how to provide an `appId` as a query parameter in the request. The response returns the field values for the request.\n\n**Request** \n\n```scdoc\nGET https://www.googleapis.com/drive/v3/apps/APP_ID\n```\n\n**Response** \n\n```scdoc\n{\n \"kind\": \"drive#app\",\n \"id\": \"ID\",\n \"name\": \"Google Sheets\",\n \"supportsCreate\": true,\n \"supportsImport\": true,\n \"supportsMultiOpen\": false,\n \"supportsOfflineCreate\": true,\n \"productUrl": \"https://chrome.google.com/webstore/detail/felcaaldnbdncclmgdcncolpebgiejap\",\n \"productId\": \"PRODUCT_ID\"\n}\n```\n\nThe response includes the following values:\n\n- \u003cvar translate=\"no\"\u003eID\u003c/var\u003e: the app ID.\n- \u003cvar translate=\"no\"\u003ePRODUCT_ID\u003c/var\u003e: the product listing ID for this app.\n\nRelated topics\n\nHere are a few next steps you might try:\n\n- To create a file in Drive, see [Create and manage files](/workspace/drive/api/guides/create-file).\n\n- To upload file data when you create or update a file, see [Upload file\n data](/workspace/drive/api/guides/manage-uploads).\n\n- To download and export files, see [Download and export\n files](/workspace/drive/api/guides/manage-downloads)."]]