Drive Activity API 数据模型
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南介绍了 Google Drive Activity API 中响应的主要组成部分,并提供了示例以及如何解读这些示例。
对象
DriveActivity
:这是对 Drive Activity API 的查询返回的主要资源。它描述一个或多个执行一项或多项操作的操作者,这些操作会影响一个或多个目标。
Timestamp
和 TimeRange
:这两个参数分别描述了活动发生的单个时间点,或活动在一段时间内发生的开始和结束时间。
Actor
:通常,Actor
是最终用户。不过,有时,当管理员以用户身份或以自己的身份执行操作,或者由无法识别的人员执行操作时,系统事件可能会触发 Action
。Actor
消息封装了每种情况。
Target
:Target
是 activity 的对象,例如文件、文件夹、共享云端硬盘或文件评论。请注意,许多操作类型支持多种类型的目标。例如,虽然 Edit
通常适用于云端硬盘文件,但 Rename
和 Create
等其他操作也可以应用于云端硬盘文件夹和共享云端硬盘。非云端硬盘项的目标仍可引用云端硬盘项,例如云端硬盘的根文件夹或包含文件评论的父级文档。
Action
:每个 DriveActivity
资源都有一个或多个相关操作。Action
是一个独立的类型,就像事件一样,它不仅包含有关操作的详细类型和信息,还包含 Actor
、Target
以及 Timestamp
或 TimeRange
。为避免冗余,当 Action
的 Target
、Actor
或时间字段与整体 DriveActivity
相同时,不会填充自己的 Target
、Actor
或时间字段。
ActionDetail
:这是 Action
的具体类型和详细信息。例如,Move
操作详情具有来源和目的地位置,PermissionChange
用于指定哪些人现在可以访问文档以及他们拥有哪些权限。
示例回复
请查看以下内容,了解示例响应。
用户修改了云端硬盘中的文件
一个 DriveActivity
资源可能只包含一个操作,例如用户修改一个文件。
"activities":[{
"primaryActionDetail":{ "edit":{} },
"actors":[ { "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID" } } } ],
"targets":[ { "driveItem":{ "name":"items/ITEM_ID", "title":"TITLE", "file":{} } } ],
"timestamp":{ "seconds":"1536794657", "nanos":791000000 },
"actions":[ { "detail":{ "edit":{} } } ]
}]
此输出包括以下值:
- ACCOUNT_ID:用户的 ID。它可与
People API 搭配使用,以获取更多信息。
- ITEM_ID:云端硬盘内容的 ID。
- TITLE:云端硬盘内容的标题。
请注意,此响应中的 Action
对象不包含 Actor
、Target
或 timestamp
,因为它们与整体 DriveActivity
相同。
两位用户在相近的时间编辑了同一文件
使用 ConsolidationStrategy
时,系统会将相关操作划分为一个组合 DriveActivity
。在此示例中,系统将两项类似的操作进行了分组:两位不同用户执行的 Edit
操作类型。
"activities":[{
"primaryActionDetail":{ "edit":{} },
"actors":[
{ "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID_1" } } },
{ "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID_2" } } }
],
"targets":[
{ "driveItem":{ "name":"items/ITEM_ID", "title":"TITLE", "file":{} } }
],
"timeRange":{
"startTime":{ "seconds":"1541089823", "nanos":712000000 },
"endTime":{ "seconds":"1541089830", "nanos":830000000 }
},
"actions":[
{
"detail":{ "edit":{} },
"actor":{ "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID_1" } } },
"timestamp":{ "seconds":"1541089830", "nanos":830000000 }
},
{
"detail":{ "edit":{} },
"actor":{ "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID_2" } } },
"timestamp":{ "seconds":"1541089823", "nanos":712000000 }
}
]
}]
此输出包括以下值:
- ACCOUNT_ID_1:第一个用户的 ID。它可与 People API 搭配使用,以获取更多信息。
- ACCOUNT_ID_2:第二个用户的 ID。
- ITEM_ID:云端硬盘内容的 ID。
- TITLE:云端硬盘内容的标题。
请注意,此响应中的 Action
对象不包含 Target
,因为它与整个 DriveActivity
相同。
该示例还说明了应用如何仅使用 DriveActivity
中的摘要信息,而无需查看具体操作。响应表明,两位用户在一段时期内修改了指定文件。
用户将两个文件移到了新目录
在此示例中,ConsolidationStrategy
将两个相关的 Move
操作分组,因为文件同时从同一来源移到了同一目的地。
"activities":[{
"primaryActionDetail":{
"move":{
"addedParents":[ { ... } ]
"removedParents":[ { ... } ]
}
},
"actors":[ { "user":{ "knownUser":{ "personName":"people/ACCOUNT_ID" } } } ],
"targets":[
{ "driveItem":{ "name":"items/ITEM_ID_1", "title":"TITLE_1", "file":{} } },
{ "driveItem":{ "name":"items/ITEM_ID_2", "title":"* TITLE_2", "file":{} } }
],
"timestamp":{ "seconds":"1541090960", "nanos":985000000 },
"actions":[
{
"detail":{ "move":{ "addedParents":[ { ... } ] "removedParents":[ { ... } ] } },
"target":{ "driveItem":{ "name":"items/ITEM_ID_1", "title":"TITLE_1", "file":{} } }
},
{
"detail":{ "move":{ "addedParents":[ { ... } ] "removedParents":[ { ... } ] } },
"target":{ "driveItem":{ "name":"items/ITEM_ID_2", "title":"* TITLE_2", "file":{} } }
}
]
}]
此输出包括以下值:
- ACCOUNT_ID:用户的 ID。它可与
People API 搭配使用,以获取更多信息。
- ITEM_ID_1:第一个云端硬盘项的 ID。
- ITEM_ID_2:第二个云端硬盘内容的 ID。
- TITLE_1:第一个云端硬盘项的标题。
- TITLE_2:第二个云端硬盘内容的标题。
请注意,此响应中的 Action
对象不包含 Actor
或 timestamp
,因为它们与整个 DriveActivity
相同。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Drive Activity API data model\n\nThis guide explains the main components of a response in the Google Drive Activity API,\nshowing examples and how to interpret them.\n\nObjects\n-------\n\n- [`DriveActivity`](/drive/activity/v2/reference/rest/v2/activity/driveactivity): This is the primary\n resource returned by queries to the Drive Activity API. It describes one\n or more actors performing one or more actions affecting one or more targets.\n\n- [`Timestamp`](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp)\n and [`TimeRange`](/drive/activity/v2/reference/rest/v2/activity/timerange): These describe,\n respectively, either a single point in time when the activity occurred, or\n the start and end of when the activity occurred over a span of time.\n\n- [`Actor`](/drive/activity/v2/reference/rest/v2/activity/actor): Typically, an `Actor` is an end user.\n However, sometimes, a system event can trigger an [`Action`](/drive/activity/v2/reference/rest/v2/activity/action) when an administrator is acting as a user or as\n themselves, or when performed by an unidentifiable person. The `Actor`\n message encapsulates each of these cases.\n\n- [`Target`](/drive/activity/v2/reference/rest/v2/activity/target): A `Target` is the object of an\n activity, like a file, a folder, a shared drive, or a file comment. Note\n that many action types support more than one kind of target. For example,\n though `Edit` generally applies to Drive files, other actions\n like `Rename` and `Create` can also apply to Drive folders\n and shared drives. Targets that aren't Drive items can still\n refer to one, such as the root folder of a drive or the parent document\n containing a file comment.\n\n- [`Action`](/drive/activity/v2/reference/rest/v2/activity/action): Each `DriveActivity` resource has one\n or more related actions. An `Action` is self-contained, like an\n *event* , in that it comprises not only the detailed type and information\n about the action, but also an `Actor`, a `Target`, and either a `Timestamp`\n or `TimeRange`. To avoid redundancy, an `Action` doesn't populate its own\n `Target`, `Actor`, or time fields when those are the same as the overall\n `DriveActivity`.\n\n- [`ActionDetail`](/drive/activity/v2/reference/rest/v2/activity/actiondetail): This is the specific type\n and detailed information about an `Action`. For example, a `Move` action\n detail has a source and destination location, and a `PermissionChange`\n specifies who can now access a document and with what privileges.\n\nExample responses\n-----------------\n\nReview the following to see sample responses.\n\n### A user edited a file in Drive\n\nA `DriveActivity` resource might include only one action, such as a user\nediting one file. \n\n \"activities\":[{\n \"primaryActionDetail\":{ \"edit\":{} },\n \"actors\":[ { \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID\u003c/var\u003e\" } } } ],\n \"targets\":[ { \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e\", \"title\":\"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\", \"file\":{} } } ],\n \"timestamp\":{ \"seconds\":\"1536794657\", \"nanos\":791000000 },\n \"actions\":[ { \"detail\":{ \"edit\":{} } } ]\n }]\n\nThis output includes the following values:\n\n- \u003cvar translate=\"no\"\u003eACCOUNT_ID\u003c/var\u003e: the ID of the user. It can be used with the [People API](/people) to get more information.\n- \u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e: the ID of the Drive item.\n- \u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e: the title of the Drive item.\n\nNote that the `Action` object in this response doesn't include the `Actor`,\n`Target`, or `timestamp` because they're the same as the overall\n`DriveActivity`.\n\n### Two users edited the same file at similar times\n\nWhen a [`ConsolidationStrategy`](/drive/activity/v2/reference/rest/v2/activity/query#consolidationstrategy)\nis used, related actions are grouped into one combined `DriveActivity`. In this\nexample, two similar actions are grouped: one `Edit` action type from two\ndifferent users. \n\n \"activities\":[{\n \"primaryActionDetail\":{ \"edit\":{} },\n \"actors\":[\n { \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID_1\u003c/var\u003e\" } } },\n { \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID_2\u003c/var\u003e\" } } }\n ],\n \"targets\":[\n { \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e\", \"title\":\"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\", \"file\":{} } }\n ],\n \"timeRange\":{\n \"startTime\":{ \"seconds\":\"1541089823\", \"nanos\":712000000 },\n \"endTime\":{ \"seconds\":\"1541089830\", \"nanos\":830000000 }\n },\n \"actions\":[\n {\n \"detail\":{ \"edit\":{} },\n \"actor\":{ \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID_1\u003c/var\u003e\" } } },\n \"timestamp\":{ \"seconds\":\"1541089830\", \"nanos\":830000000 }\n },\n {\n \"detail\":{ \"edit\":{} },\n \"actor\":{ \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID_2\u003c/var\u003e\" } } },\n \"timestamp\":{ \"seconds\":\"1541089823\", \"nanos\":712000000 }\n }\n ]\n }]\n\nThis output includes the following values:\n\n- \u003cvar translate=\"no\"\u003eACCOUNT_ID_1\u003c/var\u003e: the ID of the first user. It can be used with the [People API](/people) to get more information.\n- \u003cvar translate=\"no\"\u003eACCOUNT_ID_2\u003c/var\u003e: the ID of the second user.\n- \u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e: the ID of the Drive item.\n- \u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e: the title of the Drive item.\n\nNote that the `Action` object in this response doesn't include the `Target`\nbecause it's the same as the overall `DriveActivity`.\n\nThe example also illustrates how apps might use only the summary information in\n`DriveActivity`, without looking at the individual actions. The response\nindicates that two users edited a given file over a span of time.\n\n### A user moved two files into a new directory\n\nIn this example, the `ConsolidationStrategy` grouped two related `Move` actions\nbecause the files were moved from the same source to the same destination at the\nsame time. \n\n \"activities\":[{\n \"primaryActionDetail\":{\n \"move\":{\n \"addedParents\":[ { ... } ]\n \"removedParents\":[ { ... } ]\n }\n },\n \"actors\":[ { \"user\":{ \"knownUser\":{ \"personName\":\"people/\u003cvar translate=\"no\"\u003eACCOUNT_ID\u003c/var\u003e\" } } } ],\n \"targets\":[\n { \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID_1\u003c/var\u003e\", \"title\":\"\u003cvar translate=\"no\"\u003eTITLE_1\u003c/var\u003e\", \"file\":{} } },\n { \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID_2\u003c/var\u003e\", \"title\":\"* \u003cvar translate=\"no\"\u003eTITLE_2\u003c/var\u003e\", \"file\":{} } }\n ],\n \"timestamp\":{ \"seconds\":\"1541090960\", \"nanos\":985000000 },\n \"actions\":[\n {\n \"detail\":{ \"move\":{ \"addedParents\":[ { ... } ] \"removedParents\":[ { ... } ] } },\n \"target\":{ \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID_1\u003c/var\u003e\", \"title\":\"\u003cvar translate=\"no\"\u003eTITLE_1\u003c/var\u003e\", \"file\":{} } }\n },\n {\n \"detail\":{ \"move\":{ \"addedParents\":[ { ... } ] \"removedParents\":[ { ... } ] } },\n \"target\":{ \"driveItem\":{ \"name\":\"items/\u003cvar translate=\"no\"\u003eITEM_ID_2\u003c/var\u003e\", \"title\":\"* \u003cvar translate=\"no\"\u003eTITLE_2\u003c/var\u003e\", \"file\":{} } }\n }\n ]\n }]\n\nThis output includes the following values:\n\n- \u003cvar translate=\"no\"\u003eACCOUNT_ID\u003c/var\u003e: the ID of the user. It can be used with the [People API](/people) to get more information.\n- \u003cvar translate=\"no\"\u003eITEM_ID_1\u003c/var\u003e: the ID of the first Drive item.\n- \u003cvar translate=\"no\"\u003eITEM_ID_2\u003c/var\u003e: the ID of the second Drive item.\n- \u003cvar translate=\"no\"\u003eTITLE_1\u003c/var\u003e: the title of the first Drive item.\n- \u003cvar translate=\"no\"\u003eTITLE_2\u003c/var\u003e: the title of the second Drive item.\n\nNote that the `Action` object in this response doesn't include the `Actor` or\n`timestamp` because they're the same as the overall `DriveActivity`."]]