Drive Activity API データモデル
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このガイドでは、Google Drive Activity API のレスポンスの主なコンポーネントについて説明します。また、サンプルとその解釈方法も示します。
オブジェクト
DriveActivity
: これは、Drive Activity API へのクエリによって返されるプライマリ リソースです。1 つ以上のターゲットに影響する 1 つ以上のアクションを実行する 1 つ以上のアクターを記述します。
Timestamp
と TimeRange
: それぞれ、アクティビティが発生した単一の時点、または一定期間にわたってアクティビティが発生した開始時と終了時を記述します。
Actor
: 通常、Actor
はエンドユーザーです。ただし、管理者がユーザーまたは自身として操作している場合や、身元不明のユーザーによって操作されている場合、システム イベントによって Action
がトリガーされることがあります。Actor
メッセージは、これらのケースをそれぞれカプセル化します。
Target
: Target
は、ファイル、フォルダ、共有ドライブ、ファイル コメントなどのアクティビティのオブジェクトです。多くのアクション タイプは、複数の種類のターゲットをサポートしています。たとえば、Edit
は通常ドライブ ファイルに適用されますが、Rename
や Create
などの他のアクションは、ドライブのフォルダや共有ドライブにも適用できます。ドライブのアイテムではないターゲットでも、ドライブのルートフォルダやファイルコメントを含む親ドキュメントなど、ドライブのアイテムを参照できます。
Action
: 各 DriveActivity
リソースには、1 つ以上の関連アクションがあります。Action
は、アクションの詳細なタイプと情報だけでなく、Actor
、Target
、Timestamp
または TimeRange
も含む点で、イベントのように自己完結型です。冗長性を回避するため、Action
は、全体的な DriveActivity
と同じである場合、独自の Target
、Actor
、時間フィールドに入力しません。
ActionDetail
: Action
の特定のタイプと詳細情報です。たとえば、Move
アクションの詳細には送信元と送信先の場所があり、PermissionChange
にはドキュメントにアクセスできるユーザーとその権限を指定します。
返信の例
以下に、レスポンスの例を示します。
ユーザーがドライブでファイルを編集しました
DriveActivity
リソースには、ユーザーが 1 つのファイルを編集するなど、1 つのアクションのみを含めることができます。
"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
全体と同じであるためです。
2 人のユーザーが同じファイルをほぼ同時に編集した
ConsolidationStrategy
を使用すると、関連するアクションが 1 つの結合 DriveActivity
にグループ化されます。この例では、2 つの類似したアクションがグループ化されています。2 人の異なるユーザーによる 1 つの 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: 2 番目のユーザーの ID。
- ITEM_ID: ドライブ アイテムの ID。
- TITLE: ドライブ アイテムのタイトル。
このレスポンスの Action
オブジェクトには Target
が含まれていません。これは、DriveActivity
全体と同じであるためです。
この例は、アプリが個々のアクションを調べることなく、DriveActivity
の概要情報のみを使用する方法も示しています。レスポンスは、2 人のユーザーが特定のファイルを一定期間にわたって編集したことを示しています。
ユーザーが 2 つのファイルを新しいディレクトリに移動した
この例では、ファイルが同じソースから同じ宛先に同時に移動されたため、ConsolidationStrategy
は 2 つの関連する 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: 2 番目のドライブ アイテムの ID。
- TITLE_1: 最初のドライブ アイテムのタイトル。
- TITLE_2: 2 番目のドライブ アイテムのタイトル。
このレスポンスの Action
オブジェクトには、Actor
や timestamp
が含まれていません。これは、Actor
と timestamp
が全体的な DriveActivity
と同じであるためです。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-03-26 UTC。
[null,null,["最終更新日 2025-03-26 UTC。"],[],[],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`."]]