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 時,系統可能不會回報 Google 雲端硬碟的某些活動。Google Drive Activity API 是否會回報物件的特定變更,取決於經過驗證的使用者是否能在應用程式中看到該變更或變更相關資訊。
可見度取決於物件的權限設定。在雲端硬碟中,檔案和資料夾的共用情形有幾種:
- 如果作者共用文件,則文件的活動記錄不僅會顯示給建立者,也會顯示給共用對象 (已通過驗證的使用者)。
- 如果文件曾與使用者共用,但後來設為私人文件,通過驗證的使用者可以查看他們擁有存取權時的所有活動記錄,以及權限現在受到限制。
- 如果文件從未與使用者共用,使用者就無法查看任何活動記錄。
開始使用
如要充分運用 Drive Activity API,請先將應用程式與 Google Drive API 整合。如要開始使用 Drive Activity API,請瞭解如何建立專案和授權要求。或者,您也可以直接參閱 API 參考資料,瞭解活動。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-04 (世界標準時間)。
[null,null,["上次更新時間: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)."]]