Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này giải thích các thành phần chính của một phản hồi trong API Hoạt động trên Google Drive, đưa ra ví dụ và cách diễn giải các thành phần đó.
Đối tượng
DriveActivity: Đây là tài nguyên chính mà các truy vấn trả về cho API Hoạt động trong Drive. Mô tả một hoặc nhiều thực thể thực hiện một hoặc nhiều hành động ảnh hưởng đến một hoặc nhiều mục tiêu.
Timestamp và TimeRange: Các giá trị này mô tả lần lượt một thời điểm duy nhất khi hoạt động xảy ra hoặc thời điểm bắt đầu và kết thúc khi hoạt động xảy ra trong một khoảng thời gian.
Actor: Thông thường, Actor là người dùng cuối.
Tuy nhiên, đôi khi, một sự kiện hệ thống có thể kích hoạt Action khi quản trị viên đang đóng vai trò là người dùng hoặc chính họ, hoặc khi một người không xác định thực hiện. Thông báo Actor đóng gói từng trường hợp trong số này.
Target: Target là đối tượng của một hoạt động, chẳng hạn như tệp, thư mục, ổ đĩa dùng chung hoặc nhận xét về tệp. Xin lưu ý rằng nhiều loại hành động hỗ trợ nhiều loại mục tiêu. Ví dụ: mặc dù Edit thường áp dụng cho các tệp trên Drive, nhưng các thao tác khác như Rename và Create cũng có thể áp dụng cho thư mục trên Drive và bộ nhớ dùng chung. Các mục tiêu không phải là mục trên Drive vẫn có thể tham chiếu đến một mục, chẳng hạn như thư mục gốc của một ổ hoặc tài liệu mẹ chứa nhận xét về tệp.
Action: Mỗi tài nguyên DriveActivity có một hoặc nhiều thao tác liên quan. Action là một loại dữ liệu độc lập, giống như một sự kiện, trong đó không chỉ bao gồm loại và thông tin chi tiết về hành động, mà còn bao gồm Actor, Target và Timestamp hoặc TimeRange. Để tránh trùng lặp, Action không điền sẵn các trường Target, Actor hoặc thời gian của riêng nó khi các trường đó giống với DriveActivity tổng thể.
ActionDetail: Đây là loại cụ thể và thông tin chi tiết về Action. Ví dụ: thông tin chi tiết về hành động Move có vị trí nguồn và đích đến, còn PermissionChange chỉ định người hiện có thể truy cập vào tài liệu và có những đặc quyền nào.
Ví dụ về câu trả lời
Hãy xem nội dung sau để biết các câu trả lời mẫu.
Người dùng đã chỉnh sửa một tệp trong Drive
Một tài nguyên DriveActivity có thể chỉ bao gồm một hành động, chẳng hạn như người dùng chỉnh sửa một tệp.
ACCOUNT_ID: mã nhận dạng của người dùng. Bạn có thể sử dụng API này với
API People để biết thêm thông tin.
ITEM_ID: mã nhận dạng của mục trên Drive.
TITLE: tiêu đề của mục trên Drive.
Xin lưu ý rằng đối tượng Action trong phản hồi này không bao gồm Actor, Target hoặc timestamp vì các đối tượng này giống với DriveActivity tổng thể.
Hai người dùng đã chỉnh sửa cùng một tệp vào thời điểm tương tự nhau
Khi sử dụng ConsolidationStrategy, các thao tác có liên quan sẽ được nhóm thành một DriveActivity kết hợp. Trong ví dụ này, hai hành động tương tự nhau được nhóm lại với nhau: một loại hành động Edit của hai người dùng khác nhau.
ACCOUNT_ID_1: mã nhận dạng của người dùng đầu tiên. Bạn có thể sử dụng API này với API People để biết thêm thông tin.
ACCOUNT_ID_2: mã nhận dạng của người dùng thứ hai.
ITEM_ID: mã nhận dạng của mục trên Drive.
TITLE: tiêu đề của mục trên Drive.
Xin lưu ý rằng đối tượng Action trong phản hồi này không bao gồm Target vì đối tượng này giống với DriveActivity tổng thể.
Ví dụ này cũng minh hoạ cách các ứng dụng có thể chỉ sử dụng thông tin tóm tắt trong DriveActivity mà không xem xét từng hành động. Phản hồi cho biết hai người dùng đã chỉnh sửa một tệp nhất định trong một khoảng thời gian.
Người dùng đã di chuyển hai tệp vào một thư mục mới
Trong ví dụ này, ConsolidationStrategy đã nhóm hai thao tác Move liên quan với nhau vì các tệp được di chuyển từ cùng một nguồn đến cùng một đích đến cùng một lúc.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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`."]]