Drive Activity API 資料模型
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南說明 Google Drive Activity API 回應的主要元件,並提供示例和解讀方法。
物件
DriveActivity
:這是 Drive Activity API 查詢傳回的主要資源。它描述一個或多個執行者執行一或多個動作,進而影響一或多個目標。
Timestamp
和 TimeRange
:分別描述活動發生的單一時間點,或活動在一段時間內發生的開始和結束時間。
Actor
:通常,Actor
是使用者。不過,有時候系統事件可能會在管理員以使用者或自身身分執行動作,或是由無法辨識的使用者執行動作時,觸發 Action
。Actor
訊息會封裝這些情況。
Target
:Target
是活動的物件,例如檔案、資料夾、共用雲端硬碟或檔案註解。請注意,許多動作類型支援多種目標。舉例來說,雖然 Edit
通常會套用至雲端硬碟檔案,但其他動作 (例如 Rename
和 Create
) 也可以套用至雲端硬碟資料夾和共用雲端硬碟。非雲端硬碟項目的目標仍可參照雲端硬碟項目,例如雲端硬碟的根資料夾,或是包含檔案註解的父項文件。
Action
:每個 DriveActivity
資源都有一或多個相關動作。Action
是獨立的類型,就像事件一樣,不僅包含動作的詳細類型和相關資訊,還包含 Actor
、Target
和 Timestamp
或 TimeRange
。為避免重複,如果 Action
的 Target
、Actor
或時間欄位與整體 DriveActivity
相同,就不會填入資料。
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:第一個 Google 雲端硬碟項目的標題。
- TITLE_2:第二個 Google 雲端硬碟項目的標題。
請注意,這個回應中的 Action
物件不包含 Actor
或 timestamp
,因為它們與整體 DriveActivity
相同。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-03-26 (世界標準時間)。
[null,null,["上次更新時間: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`."]]