Google Drive Activity API 简介
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google Drive Activity API 包含 DriveActivity
资源(表示对用户 Google 云端硬盘中的对象进行的更改)和 activity.query
方法(用于检索与这些更改相关的信息)。
请求
您的应用使用 activity.query
方法请求用户活动数据。您可以请求特定云端硬盘项目或云端硬盘文件夹中包含的所有内容的活动。对于给定的请求,您可以选择通过时间范围或操作类型等限制条件来限制响应,也可以选择在响应中整合活动。如需了解详情,请参阅在 Drive Activity API 中发出请求。
响应
对请求的响应是与指定参数匹配的活动列表,其中 DriveActivity
资源表示每项活动:
DriveActivity
资源是 Action
对象的集合,每个对象都像活动一样自成一体。Action
包括 ActionDetail
(例如 Create
或 Edit
)、Actor
(例如 User
或 Administrator
)、Target
(例如 DriveItem
或 Drive
),以及 Timestamp
或 TimeRange
。
DriveActivity
资源还包含摘要信息,例如所有操作的每个 Actor
和 Target
、统一的 Timestamp
或 TimeRange
,以及 Action
的最重要或最具代表性的 ActionDetail
。
如需了解详情,请参阅 Drive Activity API 数据模型。
活动记录的可见性
使用此 API 时,系统可能不会报告云端硬盘上的某些活动。Drive Activity API 是否会报告对对象的特定更改,取决于经过身份验证的用户是否可以在您的应用中看到相应更改或与相应更改相关的信息。
可见性取决于为对象设置的权限。在云端硬盘中共享文件和文件夹时,有以下几种情况:
- 如果作者共享文档,则不仅创建者可以查看该文档的活动历史记录,经过身份验证的共享对象也可以查看。
- 如果某个文档曾与用户共享,但后来设为私密,则已通过身份验证的用户可以查看其拥有访问权限期间的所有活动记录,以及权限现在受到限制。
- 如果文档从未与用户共享,则该用户无法查看任何活动历史记录。
开始使用
如需充分利用 Drive Activity API,请先将您的应用与 Google Drive API 集成。如需开始使用 Drive Activity API,请了解如何创建项目和授权请求。或者,直接深入了解 API 参考文档中的 activity。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):2025-08-04。"],[],[],null,["# Introduction to Google Drive Activity API\n\nThe Google Drive Activity API consists of the\n[`DriveActivity`](/workspace/drive/activity/v2/reference/rest/v2/activity/driveactivity) resource, which\nrepresents changes made to objects within a user's Google Drive, and the\n[`activity.query`](/workspace/drive/activity/v2/reference/rest/v2/activity/query) method, which allows you to retrieve\ninformation about those changes.\n\nRequest\n-------\n\nYour app requests a user's activity data using the\n[`activity.query`](/workspace/drive/activity/v2/reference/rest/v2/activity/query) method. You can request activity\neither for a specific Drive item or for everything contained under a Drive\nfolder. For a given request, you can choose to restrict the response by\n[constraints](/workspace/drive/activity/v2/requests#filters) such as time range or action type, and you\ncan choose to have the activity [consolidated](/workspace/drive/activity/v2/requests#consolidation) in the\nresponse. For more information, see [Make requests in the Drive Activity API](/workspace/drive/activity/v2/requests).\n\nResponse\n--------\n\nThe response to a request is a list of activities matching the given parameters,\nwhere a\n[`DriveActivity`](/workspace/drive/activity/v2/reference/rest/v2/activity/driveactivity) resource represents each activity:\n\nA [`DriveActivity`](/workspace/drive/activity/v2/reference/rest/v2/activity/driveactivity) resource is a collection of\n[`Action`](/workspace/drive/activity/v2/reference/rest/v2/activity/action) objects, each of which is\nself-contained like an *event* . An `Action` includes an\n[`ActionDetail`](/workspace/drive/activity/v2/reference/rest/v2/activity/actiondetail) (such as `Create`\nor `Edit`), an [`Actor`](/workspace/drive/activity/v2/reference/rest/v2/activity/actor) (such as `User`\nor `Administrator`), a [`Target`](/workspace/drive/activity/v2/reference/rest/v2/activity/target) (such\nas `DriveItem` or `Drive`), and either a\n[`Timestamp`](/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Timestamp)\nor [`TimeRange`](/workspace/drive/activity/v2/reference/rest/v2/activity/timerange).\n\nA `DriveActivity` resource also contains\nsummary information, such as every\n`Actor` and\n`Target` from all the actions, a unified\n`Timestamp`\nor `TimeRange`, and either the most\nimportant or representative\n`ActionDetail` of the\n`Action`.\n\nFor more information, see the [Drive Activity API data model](/workspace/drive/activity/v2/datamodel).\n\nActivity history visibility\n---------------------------\n\nSome activity on Drive may not be reported when you use this API. Whether the\nDrive Activity API reports a given change to an object depends on whether\nthe change, or information about the change, is visible to the authenticated\nuser in your application.\n\nVisibility is based on the permissions set for the object. There's several\nscenarios when files and folders are shared in Drive:\n\n- If an author shares a document, the activity history for the document is visible to not only the creator, but also to the authenticated users with whom it was shared.\n- If a document was shared with a user and then made private, the authenticated user can see all activity history while they had access and that the permissions are now restricted.\n- If a document was never shared with a user, the user can't see any activity history.\n\nGet started\n-----------\n\nTo get the most out of the Drive Activity API, integrate your app with the\n[Google Drive API](/workspace/drive/api) first. To get started with the Drive Activity API,\nlearn how to [create a project](/workspace/drive/activity/v2/guides/project) and\n[authorize requests](/workspace/guides/configure-oauth-consent). Or, dive right in and read\nabout activities in the\n[API reference](/workspace/drive/activity/v2/reference/rest/v2/activity)."]]